Guess a Number program. There are two versions of the guess a number program att
ID: 3734617 • Letter: G
Question
Guess a Number program. There are two versions of the guess a number program attached to this assignment. If you struggled with the previous version, please feel free to start with one of these versions (use the one that makes the most sense to you) Make the following changes to the program 1) Have the computer choose a number between 1 and 100 instead of between 1 and 10 2) Since there is a wider range of numbers to choose from, "winning will be within 7 guesses instead of 5 make sure you make this change 3) Your program needs to tell you if you've guessed too high or too low. (This will require if statements!) 4) Your program needs to ask if the user would like to play again. If not, the program should stop. If so, the program must pick a new number to guess and allow the user to try to guess the number, printing out win/loss and the number of tries (This requires an additional while loop!)Explanation / Answer
import random wins = 0 loss = 0 while True: target = random.randint(1, 100) guess = 0 tries = 0 print "I'm going to pick a number between 1 and 100. Can you guess it?" while guess != target: guess = int(raw_input("What is your guess? ")) if guess > target: print("Too high") elif guessRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.