Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":28155,"date":"2015-11-25T20:01:59","date_gmt":"2015-11-26T02:01:59","guid":{"rendered":"http:\/\/juansalvadorfernandez.wordpress.com\/?p=180"},"modified":"2015-11-25T20:01:59","modified_gmt":"2015-11-26T02:01:59","slug":"text-based-user-input-and-validation-in-python","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2015\/2015\/text-based-user-input-and-validation-in-python\/","title":{"rendered":"Text based User input and Validation in Python"},"content":{"rendered":"

The user input allows you to get your program to interact with a living being, the user. This can be helpful when you desire to get a value you have no control over, for instance a variable. It can also be applied to quickly test a program with multiple values many times.<\/p>\n

To ask the user for a value or \u201cinput\u201d, you first have to assign a variable to that value, next you use the \u201cinput\u201d command to tell the computer to read and save in the variable we just created whatever the user types on the keyboard. After the \u201cinput\u201d command you have to actually ask the user for the information that you desire to obtain, for example: \u201cHow many fingers do you have?\u201d, then the user should answer the question returning the information and the input will assign that value to the variable we created.<\/p>\n

X = input (\u201cHow many fingers do you have?\u201d), user writes \u201c5\u201d, then \u201cX = 5\u201d<\/p>\n

Although it is easy to write and very practical in itself, the fact that it generates a human-machine interaction can bring us many problems. For instance, we take it as granted that everyone has five fingers in each hand, but someone can count the fingers of BOTH of their hands, or they can have an extra finger, or just screw with you and give you a random number like 196. All of this outcomes have an impact in the way your program works.<\/p>\n

Let\u2019s say that your program is: n = input (\u201cGive me a number\u201d), and while (n>0): print (\u201cNom\u201d) n=n-1. For this program you expect \u201cn\u201d to be an integer, but if the user gives you a string like \u201cBanana\u201d, then your program will die since the value of n is not valid for that condition.<\/p>\n

This is the reason why we VALIDATE the user input, so that even if we can\u2019t control what the user types we can filter that information and retrieve what we desire or just ask the user for a different input again and again until he gets it right.<\/p>\n

Following the previews example, in order to avoid the \u201cBanana\u201d error:<\/p>\n

We can use an \u201cif\u201d:<\/p>\n

n = input (\u201cGive me a number\u201d)<\/p>\n

if (n = int(n)) and (n>0):<\/p>\n

while (n>0):<\/p>\n

print (\u201cNom\u201d)<\/p>\n

n = n \u2013 1<\/p>\n

else:<\/p>\n

n = input (\u201cGive me another number\u201d)<\/p>\n

With this we have two conditions that \u201cguard\u201d the while, if the value of \u201cn\u201d is an integer and it is greater than zero then we can proceed with the loop, any other values will be discarded and the user will be asked for a new one. Of course there are lots of ways to validate, this was just an example of what you could do in this specific situation.<\/p>\n

\"\"<\/a> \"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

The user input allows you to get your program to interact with a living being, the user. This can be helpful when you desire to get a value you have no control over, for instance a variable. It can also be applied to quickly test a program with multiple values many times. To ask the … Continue reading Text based User input and Validation in Python<\/span><\/a>\"\"<\/p>\n","protected":false},"author":211,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[898,899,482,900,39],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/28155"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/users\/211"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/comments?post=28155"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/28155\/revisions"}],"predecessor-version":[{"id":28156,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/28155\/revisions\/28156"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media?parent=28155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/categories?post=28155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/tags?post=28155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}