Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5 6 # Can you guess the random integer between 1 and 20 (inclusive) in 4 trys? # Write a program that randomly chooses an

image text in transcribed

5 6 # Can you guess the random integer between 1 and 20 (inclusive) in 4 trys? # Write a program that randomly chooses an integer between 1 and 20 inclusive and then gives the user 4 chances to guess the hidden number. After each incorrect answer the computer should say that the guess was too high or too low. If the user does not guess the number after 4 trys, the computer should say: "You are out of guesses, you lose!" and then tell the user what the hidden number actually was. import random import math 11 x = math.floor(20*random.random()) + 1 print("X = " , x) print("Guess a number between 1 and 20: ") guess = float(input() if(guess == x) : print("You win! The number is" , x) else: # all additional code goes inside of this else statement! Why? #1 figure out if the guess is too high or too low and then let the user know guess too high or too low #2 let user make another guess #3 find out if the user won (is the guess correct?) #if yes then inform user that they are correct and have won and the game now ends #if no then repeat the steps! print("hi") # remove this "hi" statement from your code. It is only here because Python requires that there be some code inside of an else statement that you create and I wanted to give you a Skeleton that you could run (even though it doesn't behave as desired until you write the needed code!)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

Students also viewed these Databases questions

Question

Does the periodic payment remain constant over time?

Answered: 1 week ago