293,052 views
6 votes
6 votes
I need help to fill in a few blanks with this coding homework. did some, but need help on the rest. the assignment is down below

# Cody Ryan, 4/28/2022, this is coding with loops

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 Paul Hannon
by
2.9k points

1 Answer

24 votes
24 votes

Answer:

def main():

# Initialize variables

numGuesses = 0

userGuess = -1

secretNum = 5

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

while ( userGuess != secretNum):

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.")

print("You guessed " + str(userGuess) + ". The correct number is " + secretNum + " after " + numGuess + " times.")

main()

Step-by-step explanation:

add a While until userGuess == secretNum than we stop

User Reisa
by
2.8k points