In: Computer Science
Please make a Python program where the computer chooses a number and the player guesses the number.
You need an input, a random number, if statement, and a while loop.
Please reference these when doing the code:
((random reference))
•>>> import random
•>>> random.randint(1, 100)
•67
((While & if referefence))
•>>> cnum = 3
•>>>while true
•>>> if cnum == 3:
•>>> print(‘correct’)
•>>> break
•>>> elif cnum == 2:
•>>> print(‘incorrect’)
Please prepare a Word document that has the Python code and the screen shot of your output.
Here is a sample output screen.
What is your guess? 97 Too high What is your guess? 6 Too low What is your guess? 82 Too high What is your guess? 23 Too low What is your guess? 64 Too high What is your guess? 46 Too high What is your guess? 35 Too low What is your guess? 40 Too high What is your guess? 37 Too low What is your guess? 39 Too high What is your guess? 38 Correct ! >>> |
import random
number = random.randint(1,100)
total_guess = 0
while total_guess<=100:
guess = int(input("what is your guess?"))
print (guess)
total_guess = total_guess + 1
if guess<number:
print("Too low")
if guess>number:
print("Too high")
if guess==number:
print("Correct!")
break
21 import random number = random.randint(1,100) total_guess = 0 while total_guess<=100: guess = int(input("what is your guess?")) print guess) total_guess = total_guess + 1 if guess<number: print("Too low") if guess>number: print("Too high") if guess==number: print("Correct!") break what is your guess?40 40 Too high what is your guess?20 20 Too low what is your guess?30 30 Too high what is your guess?25 25 Too low what is your guess?27 27 Too low what is your guess?29 29 Too high what is your guess?28 28 Correct!