{"id":94,"date":"2024-12-31T05:43:59","date_gmt":"2024-12-31T05:43:59","guid":{"rendered":"https:\/\/python.freelinuxtutorials.com\/?p=94"},"modified":"2024-12-31T05:43:59","modified_gmt":"2024-12-31T05:43:59","slug":"python-project1-guess-number","status":"publish","type":"post","link":"https:\/\/python.freelinuxtutorials.com\/index.php\/2024\/12\/31\/python-project1-guess-number\/","title":{"rendered":"Python Project1: Guess Number"},"content":{"rendered":"<div>\n<div>Code:<\/div>\n<\/div>\n<div><\/div>\n<div>\n<div>\n<blockquote>\n<div>import random<\/div>\n<div>import time<\/div>\n<div>correctanswer = random.randint(1,20)<\/div>\n<div>guesscount = 1<\/div>\n<div>print(&#8220;I will be selecting numbers between 1 and 20&#8221;)<\/div>\n<div>print(&#8220;Picking a number&#8230;&#8221;)<\/div>\n<div>time.sleep(2)<\/div>\n<div>guess = int(input(&#8220;Guess a number: &#8220;))<\/div>\n<div>while guess != correctanswer:<\/div>\n<div>\u00a0 \u00a0 guesscount += 1<\/div>\n<div>\u00a0 \u00a0 if guess &lt; correctanswer:<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 guess = int(input(&#8220;You need to make it higher. Try again: &#8220;))<\/div>\n<div>\u00a0 \u00a0 else:<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 guess = int(input(&#8220;You need to make it lower. Try again: &#8220;))<\/div>\n<div>print(f&#8221;Congrats. The correct answer is {correctanswer}. It took you total of {guesscount} guesses.&#8221;)<\/div>\n<\/blockquote>\n<\/div>\n<\/div>\n<div>Sample Output:<\/div>\n<div>\n<div>I will be selecting numbers between 1 and 20<br \/>\nPicking a number&#8230;<br \/>\nGuess a number: 17<br \/>\nYou need to make it lower. Try again: 12<br \/>\nYou need to make it higher. Try again: 13<br \/>\nYou need to make it higher. Try again: 15<br \/>\nYou need to make it higher. Try again: 16<br \/>\nCongrats. The correct answer is 16. It took you total of 5 guesses.<\/div>\n<\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Code: import random import time correctanswer = random.randint(1,20) guesscount = 1 print(&#8220;I will be selecting numbers between 1 and 20&#8221;) print(&#8220;Picking a number&#8230;&#8221;) time.sleep(2) guess = int(input(&#8220;Guess a number: &#8220;)) while guess != correctanswer: \u00a0 \u00a0 guesscount += 1 \u00a0 \u00a0 if guess &lt; correctanswer: \u00a0 \u00a0 \u00a0 \u00a0 guess = int(input(&#8220;You need to make&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"footnotes":""},"categories":[24],"tags":[29,30,26,25,27,28],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-project","tag-guess","tag-number","tag-project","tag-python","tag-random","tag-time"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":3,"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions\/97"}],"wp:attachment":[{"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python.freelinuxtutorials.com\/index.php\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}