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 post 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 !
>>>
from random import randint
computer = randint(1,100)
guess = 0
while True:
num = int(input("Enter a number between 1 and 100: "))
if num > computer:
print("Number too High")
elif num < computer:
print("Number too Low")
else:
print("Awesome Congratulations !!! you guessed the number in ", guess, "attempts")
break;
guess = guess + 1
=====================================================
SEE OUTPUT/ CODE FOR INDENTATION
Thanks, PLEASE COMMENT if there is any concern.