Welcome to Westonci.ca, your ultimate destination for finding answers to a wide range of questions from experts. Explore thousands of questions and answers from a knowledgeable community of experts on our user-friendly platform. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

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

Thanks for using our service. We aim to provide the most accurate answers for all your queries. Visit us again for more insights. Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.