{"id":33117,"date":"2016-02-19T22:53:42","date_gmt":"2016-02-20T04:53:42","guid":{"rendered":"http:\/\/alextenablog.wordpress.com\/?p=190"},"modified":"2016-02-19T23:49:19","modified_gmt":"2016-02-20T05:49:19","slug":"wsq06-7","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2016\/2016\/02\/wsq06-7\/","title":{"rendered":"#WSQ06"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\" alignleft\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/3932b0da3d4c5b68d432556537b273fc.jpg\" alt=\"\" width=\"183\" height=\"183\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" alignright\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/c8fd5879665771c696da93d900fa145b.jpg\" alt=\"\" width=\"318\" height=\"181\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color:#000000;\">This code required to import a module, but what is module? \u00a0you might ask. The answer of that question is inside this page:\u00a0https:\/\/docs.python.org\/2\/tutorial\/modules.html<\/span><\/p>\n<p><span style=\"color:#000000;\">Basically a module is script or python file that cointains several functions and statements. You can import modules to the main module of python and you can also create your own. Most of the functions and statements we need by now, already exists within the python modules.\u00a0<\/span><\/p>\n<p><span style=\"color:#000000;\"><img decoding=\"async\" class=\" aligncenter\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/eaf4a1ff048dfc8f3008825513cb5d3f.jpg\" alt=\"\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color:#000000;\">But let\u00b4s get back to the assignment; for this program we need to ask the user for a random number until he guesses the exact same number that the our code has chosen randomly.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color:#000000;\"><img loading=\"lazy\" decoding=\"async\" class=\" aligncenter\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/4dfc05fb8db767859efac3f4f6af8cef.jpg\" alt=\"\" width=\"559\" height=\"193\" \/><\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color:#000000;\">-First we need to import the random module, with this module we can use a function that selects a random number of a certain range.<\/span><\/strong><\/p>\n<p><span style=\"color:#000000;\"><em>import random<\/em><\/span><\/p>\n<p><span style=\"color:#000000;\"><em>num=(random.randint(1,100))<\/em><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color:#000000;\">-After asking the user to try to guess the number, we need to impliment a while loop so the user can \u00a0have many tries until he guesses the number.\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color:#000000;\"><em>print (&#8220;I have a number chosen between 1 and 100&#8221;)<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em>print (&#8220;Try to guess that number&#8221;)<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em>countg=&#8221;guesses to get the right number&#8221;<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em>guess=0<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em>count=0<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em>while int (guess) != int (num):<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em> guess=input()<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em> count= int(count)+1<\/em><\/span><\/p>\n<p><strong><span style=\"color:#000000;\">-This code means that when the user inputs the right number the loop will end and the program will be over.<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color:#000000;\">-But that is not it, we also need to tell the user if his guess is lower or higher than the actual number. To do this I used If and else conditions.\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color:#000000;\"><em>if int(guess) &gt; int(num):<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em> print ( guess,&#8221;is too high, try again&#8221;)<\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em> if int(guess) &lt; int(num): <\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em> print(guess,&#8221;is too low, try again&#8221;)<\/em><\/span><\/p>\n<p><span style=\"color:#000000;\"><em>print(&#8220;You guessed the number!&#8221;) <\/em><\/span><br \/>\n<span style=\"color:#000000;\"><em>print(&#8220;It took you&#8221;,count,countg) \u00a0 \u00a0\u00a0<\/em><\/span><\/p>\n<p><strong><span style=\"color:#000000;\">-I also used a counter <\/p>\n<div class=\"post-limited-image\"><img decoding=\"async\" class=\"alignnone size-full wp-image-265\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/b6ab866b9f18a657415cb63aae5eaa62.jpg\" alt=\"random\"   \/><\/div>\n<div class=\"post-limited-image\"><img decoding=\"async\" class=\"alignnone size-full wp-image-269\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/02f3feb5cc1a96c4a53f53764b8e1751.jpg\" alt=\"guess\"   \/><\/div>\n<div class=\"post-limited-image\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/i2.wp.com\/www.funnymemes.com\/wp-content\/uploads\/2015\/06\/funny-memes-coding-in-a-single-night.png\" alt=\"\" width=\"690\" height=\"412\" \/><\/div>\n<div class=\"post-limited-image\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/e78af7b6b38332eb2f875194bcd7b719.jpg\" \/><\/div>\n<div class=\"post-limited-image\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/62cc64a3c7c3cb9af11e81f92ac8ccef.jpg#038;blog=105328326&#038;%23038;post=190&#038;%23038;subd=alextenablog&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div>\n<p><!--more--> counting how many times the user tried to guess the right number<\/span><\/strong><\/p>\n<p><strong><span style=\"color:#000000;\">The final code is this:<\/span><\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-265\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/b6ab866b9f18a657415cb63aae5eaa62.jpg\" alt=\"random\"   \/><\/p>\n<p><span style=\"color:#000000;\"><strong>The program looks like this:<\/strong><\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-269\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/02f3feb5cc1a96c4a53f53764b8e1751.jpg\" alt=\"guess\"   \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>And that\u00b4s it.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/i2.wp.com\/www.funnymemes.com\/wp-content\/uploads\/2015\/06\/funny-memes-coding-in-a-single-night.png\" alt=\"\" width=\"690\" height=\"412\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/alextenablog.wordpress.com\/190\/\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/e78af7b6b38332eb2f875194bcd7b719.jpg\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/02\/62cc64a3c7c3cb9af11e81f92ac8ccef.jpg#038;blog=105328326&#038;%23038;post=190&#038;%23038;subd=alextenablog&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; This code required to import a module, but what is module? \u00a0you might ask. The answer of that question is inside this page:\u00a0https:\/\/docs.python.org\/2\/tutorial\/modules.html Basically a module is script or python file that cointains several functions and statements. You can import modules to the main module of python and you &hellip; <a href=\"https:\/\/kenscourses.com\/tc101winter2016\/2016\/02\/wsq06-7\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">#WSQ06<\/span><\/a><\/p>\n","protected":false},"author":46,"featured_media":33162,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[45],"class_list":["post-33117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-sin-categoria"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/33117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/comments?post=33117"}],"version-history":[{"count":4,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/33117\/revisions"}],"predecessor-version":[{"id":33176,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/33117\/revisions\/33176"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media\/33162"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media?parent=33117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/categories?post=33117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/tags?post=33117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}