Find the best solutions to your questions at Westonci.ca, the premier Q&A platform with a community of knowledgeable experts. Connect with a community of experts ready to help you find accurate solutions to your questions quickly and efficiently. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

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()


Sagot :

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()

Explanation:

add a While until userGuess == secretNum than we stop

Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Thank you for trusting Westonci.ca. Don't forget to revisit us for more accurate and insightful answers.