{"id":39054,"date":"2016-11-23T08:43:12","date_gmt":"2016-11-23T14:43:12","guid":{"rendered":"http:\/\/a00344371.wordpress.com\/?p=317"},"modified":"2016-11-23T08:43:12","modified_gmt":"2016-11-23T14:43:12","slug":"validated-user-input-3","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/validated-user-input-3\/","title":{"rendered":"Validated user input"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/a00344371.wordpress.com\/2016\/11\/23\/validated-user-input\/\"><a href=\"https:\/\/a00344371.wordpress.com\">Programming Fundaments<\/a><\/a><\/em><br \/><\/p>\n<p>In this case you wnat the user to interact with your program; for example, if they want to\u00a0start making another accion by simply using the srings &#8220;yes&#8221; and &#8220;no&#8221;. Example:<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\"><code><span class=\"pln\">endProgram <\/span><span class=\"pun\">=<\/span> <span class=\"lit\">0<\/span><span class=\"pun\">;<\/span>\n<span class=\"kwd\">while<\/span><span class=\"pln\"> endProgram <\/span><span class=\"pun\">!=<\/span> <span class=\"lit\">1<\/span><span class=\"pun\">:<\/span>\n\n    <span class=\"com\">#Prompt for a new transaction<\/span><span class=\"pln\">\n    userInput <\/span><span class=\"pun\">=<\/span><span class=\"pln\"> input<\/span><span class=\"pun\">(<\/span><span class=\"str\">\"Would you like to start a new transaction?: \"<\/span><span class=\"pun\">);<\/span><span class=\"pln\">\n    userInput <\/span><span class=\"pun\">=<\/span><span class=\"pln\"> userInput<\/span><span class=\"pun\">.<\/span><span class=\"pln\">lower<\/span><span class=\"pun\">();<\/span>\n\n    <span class=\"com\">#Validate input<\/span>\n    <span class=\"kwd\">while<\/span><span class=\"pln\"> userInput <\/span><span class=\"kwd\">in<\/span> <span class=\"pun\">[<\/span><span class=\"str\">'yes'<\/span><span class=\"pun\">,<\/span> <span class=\"str\">'no'<\/span><span class=\"pun\">]:<\/span>\n        <span class=\"kwd\">print<\/span> <span class=\"pun\">(<\/span><span class=\"str\">\"Invalid input. Please try again.\"<\/span><span class=\"pun\">)<\/span><span class=\"pln\">\n        userInput <\/span><span class=\"pun\">=<\/span><span class=\"pln\"> input<\/span><span class=\"pun\">(<\/span><span class=\"str\">\"Would you like to start a new transaction?: \"<\/span><span class=\"pun\">)<\/span><span class=\"pln\">\n        userInput <\/span><span class=\"pun\">=<\/span><span class=\"pln\"> userInput<\/span><span class=\"pun\">.<\/span><span class=\"pln\">lower<\/span><span class=\"pun\">()<\/span>\n\n    <span class=\"kwd\">if<\/span><span class=\"pln\"> userInput <\/span><span class=\"pun\">==<\/span> <span class=\"str\">'yes'<\/span><span class=\"pun\">:<\/span><span class=\"pln\">\n        endProgram <\/span><span class=\"pun\">=<\/span> <span class=\"lit\">0<\/span>\n    <span class=\"kwd\">if<\/span><span class=\"pln\"> userInput <\/span><span class=\"pun\">==<\/span> <span class=\"str\">'no'<\/span><span class=\"pun\">:<\/span><span class=\"pln\">\n        endProgram <\/span><span class=\"pun\">=<\/span> <span class=\"lit\">1<\/span><\/code><\/pre>\n<p>The last program has en error, that uin every time you answer something else it will accept it and restart the program<\/p>\n<p>It simply need a codeeditor to export it and that&#8217;s it<\/p>\n<p>Examples &amp; More at :<a href=\"http:\/\/stackoverflow.com\/questions\/16635073\/validating-user-input-strings-in-python\" rel=\"nofollow\">http:\/\/stackoverflow.com\/questions\/16635073\/validating-user-input-strings-in-python<\/a><\/p><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/a00344371.wordpress.com\/317\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/a00344371.wordpress.com\/317\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=a00344371.wordpress.com&#038;blog=115285426&%23038;post=317&%23038;subd=a00344371&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Programming Fundaments In this case you wnat the user to interact with your program; for example, if they want to\u00a0start making another accion by simply using the srings &#8220;yes&#8221; and &#8220;no&#8221;. Example: endProgram = 0; while endProgram != 1: #Prompt for a new transaction userInput = input(&#8220;Would you like to start a &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/validated-user-input-3\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Validated user input<\/span><\/a><\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[37,24,33],"class_list":["post-39054","post","type-post","status-publish","format-standard","hentry","category-blogs","category-syndicated","tag-programming","tag-python","tag-tc101"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39054","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\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=39054"}],"version-history":[{"count":5,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39054\/revisions"}],"predecessor-version":[{"id":43092,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39054\/revisions\/43092"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=39054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=39054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=39054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}