28.5k views
5 votes
What is wrong with this 50pts HURRY

# Heading (name, date, and short description) feel free to use multiple lines def main(): # Initialize variables numGuesses = 0 userGuess = -1 secretNum = 5 name = input("Hello! What is your name?") # Fill in the missing LOOP here. # This loop will need run until the player has guessed the secret number. userGuess = int(input("Guess a number between 1 and 20: ")) numGuesses = numGuesses + 1 if (userGuess < secretNum): print("You guessed " + str(userGuess) + ". Too low.") if (userGuess > secretNum): print("You guessed " + str(userGuess) + ". Too high.") # Fill in missing PRINT statement here. # Print a single message telling the player: # That he/she guessed the secret number # What the secret number was # How many guesses it took main()

User Intelfx
by
3.6k points

1 Answer

5 votes

Answer:

try:

from random import randint

except:

x=5

x=randint(1, 20)

numGuesses, userGuess, secretNum = 0, 0, x

name = str(input("Hello! What is your name? "))

while True:

numGuesses+=1

userGuess=int(input("Guess a number from 1 to 20: "))

if userGuess < secretNum:

print("Too low, try again.")

elif userGuess > secretNum:

print("Too high, try again.")

else:

break

print("The number was "+str(secretNum)+", and " + name + " guessed it in "+str(numGuesses)+" guesses!")

User BlueMark
by
4.4k points