adding to this program :option for the computer to guess as well as
adding to this program :option for the computer to guess as well as
the user to guess a number. import random at the beginning of your code and use a comment block explaining what your program doesa menu system.
old code
print(“Welcome to my Guess the number program!”)
import random at the beginning of your code and use a comment block explaining what your program does
mynumber = random.randint(1, 10)
counter = 0
while (True):
try:
counter += 1
guess = int(input(“Gues a number between 1 and 10: “))
if guess < 1 or guess > 10:
print(“Please enter a number between 1 and 10”)
else:
if (guess < mynumber):
print(“Too low”)
elif (guess > mynumber):
print(“Too high”)
elif (guess == mynumber):
print(“You guessed it!”)
print(” in “, counter, ” guesses”)
break
except:
print(“Numbers only!.”)
ATTACHMENT PREVIEW Download attachment

Screen Shot 2019-02-17 at 11.51.36 AM.png
1I.r"I."hen you run the program you should see something like the following:
1I.r"I.’e|come to my Guess the number program! 1. You guess the number
2. You type a number and see if the computer can guess it
3. Exit 1What is your choice: 1 Please guess a number between 1 and 1t]: 3
Too high Please guess a number between 1 and 1t]: 1"
You guessed it! it tool: you 2 attempts 1. You guess the number
2. You type a number and see if the computer can guess it
3. Exit 1What is your choice: 2 Please enter a number between 1 and 1D for the computer to guess: 5
The computer guessed i" which is too high The computer guessed 2 which is too low The computer guessed El which is too high The computer guessed E which is too high The computer guessed ti which is too high The computer guessed 1 which is too low