{"id":39032,"date":"2016-11-23T08:11:39","date_gmt":"2016-11-23T14:11:39","guid":{"rendered":"http:\/\/edalitablog.wordpress.com\/?p=601"},"modified":"2016-11-23T08:11:39","modified_gmt":"2016-11-23T14:11:39","slug":"validating-user-input-in-python","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/validating-user-input-in-python\/","title":{"rendered":"Validating User Input in Python"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/edalitablog.wordpress.com\/2016\/11\/23\/validating-user-input-in-python\/\"><a href=\"https:\/\/edalitablog.wordpress.com\">Ed_Alita<\/a><\/a><\/em><br \/><\/p>\n<p>&nbsp;<\/p>\n<h2>User do not know how to use a computer<\/h2>\n<p><a class=\"quuv-DXgx1bDAVbujXFOD\" style=\"width:248px;height:139px;\" href=\"http:\/\/giphy.com\/gifs\/spongebob-l46CyJmS9KUbokzsI\"><img class=\"_3QcZOBs-_0PFoUjz21NMOt aligncenter\" src=\"https:\/\/media2.giphy.com\/media\/l46CyJmS9KUbokzsI\/200.gif#9\" width=\"248\" height=\"139\" \/><\/a><\/p>\n<p>This mentally you need to have in order to have a great code.<\/p>\n<p>Lets see if I have the next code:<\/p>\n<p><img class=\"alignnone size-full wp-image-609\" src=\"https:\/\/edalitablog.files.wordpress.com\/2016\/11\/validating.gif?w=748\" alt=\"validating\"   \/><\/p>\n<p>If the user gave you for any reason a letter because he or she is stupid the code will crash:<\/p>\n<p><img class=\"alignnone size-full wp-image-608\" src=\"https:\/\/edalitablog.files.wordpress.com\/2016\/11\/validating-2gif.gif?w=748\" alt=\"validating-2gif\"   \/><\/p>\n<p>In order to prevent this we are going to validate what the user gave us is corect in this case first we are going to obtain the input without any type we do this by puting raw_input.<\/p>\n<p>the next thing is to do the text if it is a number with int(User_Input). since we know that if this obtain a number it will crash we are going to do a cheat to stop this.<\/p>\n<p>We use Try and except:<\/p>\n<p>What try does it proves the code and Except will do an action if the codecrash.<\/p>\n<p>The complete code will look like this:<\/p>\n<p><img class=\" size-full wp-image-621 aligncenter\" src=\"https:\/\/edalitablog.files.wordpress.com\/2016\/11\/validating3.gif?w=748\" alt=\"validating3\"   \/><\/p>\n<p>In this case if the user gave us a string it should make this:<\/p>\n<p><img class=\"alignnone size-full wp-image-622\" src=\"https:\/\/edalitablog.files.wordpress.com\/2016\/11\/validating4.gif?w=748\" alt=\"validating4\"   \/><\/p>\n<p>If the user gave us a integer it should run smothly:<\/p>\n<p><img class=\"alignnone size-full wp-image-623\" src=\"https:\/\/edalitablog.files.wordpress.com\/2016\/11\/validating5.gif?w=748\" alt=\"validating5\"   \/><\/p>\n<h2>Go and Have fun as a Code Master<\/h2>\n<p><a class=\"quuv-DXgx1bDAVbujXFOD\" style=\"width:248px;height:171px;\" href=\"http:\/\/giphy.com\/gifs\/etrtLJGyXSfoQ\"><img class=\"_3QcZOBs-_0PFoUjz21NMOt aligncenter\" src=\"https:\/\/media3.giphy.com\/media\/etrtLJGyXSfoQ\/200.gif#33\" width=\"248\" height=\"171\" \/><\/a><\/p><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/edalitablog.wordpress.com\/601\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/edalitablog.wordpress.com\/601\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=edalitablog.wordpress.com&#038;blog=115122805&%23038;post=601&%23038;subd=edalitablog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Ed_Alita &nbsp; User do not know how to use a computer This mentally you need to have in order to have a great code. Lets see if I have the next code: If the user gave you for any reason a letter because he or she is stupid the code will crash: &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/validating-user-input-in-python\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Validating User Input in Python<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":609,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[78,24],"class_list":["post-39032","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-basic","tag-python"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=39032"}],"version-history":[{"count":5,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39032\/revisions"}],"predecessor-version":[{"id":42183,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39032\/revisions\/42183"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=39032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=39032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=39032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}