pls answer this fellow coders i need it so bad



# 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 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


fill in the missing code

Answers

Answer 1

This is how I would do it using the main function:

def main():

   num_guesses = 0

   secret_num = 5

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

   while True:

       user_guess = int(input("Guess a number between 1 and 20: "))

       if user_guess == secret_num:

           num_guesses += 1

           break

       elif user_guess < secret_num:

           num_guesses += 1

           print("You guessed {}. That was too low!".format(user_guess))

       elif user_guess > secret_num:

           num_guesses += 1

           print("You guessed {}. That was too high!".format(user_guess))

   print("The secret number was {}. You guessed it correctly in {} tries".format(secret_num, num_guesses))

if __name__ == "__main__":

   main()

I hope this helps!


Related Questions

Other Questions
Can you guys help me find the supplements for question 6 In the reaction between lead(II) nitrate and sodium chloride, what, if any, are the spectator ions She had told them about the place where they would stay, promising warmth and good food, holding these things out to them as an incentive to keep going.Harriet Tubman, Conductor on theUnderground Railroad, Ann PetryBy telling them about the place to stay, warmth, and good food, Tubman is appealing to which rhetorical appeal?logospathosethosthe rhetorical triangle 1. How should we interact with the world around us? Which of the following is in the order of increasing bond strength?a. Hydrogen, ionic, covalentb. Hydrogen, covalent, ionicc. Ionic, hydrogen, covalentd. Covalent, ionic, hydrogen Natasha is looking for a material to make tires for a new jogging stroller she designed. Which would be best suited to her product? 1. Which of these is not a natural fibre?a. leatherb. juteC.Woold. cotton Graph AGraph BGraph CORE2.Graph DGraph E v The French and Indian War, fought in NorthAmerica, was primarily between what 2nations? Farmer Bob's son built a track to walk his pet pig. Thetrack goes around the pig pen. The pig pen is 15 feet long and 21 feet wide. If the pig walks all the way around the track, how many feet did he walk? CAN SOMEONE PLEASE HELP ME Margaretta cleans houses. She can clean 12 houses in 10 hours. If she cleans houses at a constant rate, how many hours will it take Margaretta to clean 27 houses?please i need help What happened to enslaved Africans onced the reached the West Indies? which statement is false someone pls answer 4/16 in reduced fraction In the system of democracy in the United States, the people hold thepower of government. How does this system differ from a dictatorship?The power of the leader in a dictatorship is restricted by a written constitution.A single person controls the power of the national government in a dictatorshipThe political power of a dictatorship is dependent on the approval of a legislative body.The leader in a dictatorship must deal with the separation of government powers. The perimeter of a rectangle is 42 inches. If the width of the rectangle is 6 inches, what is the length?OA12 inchesOB. 15 inchesOC 21 inchesOD. 40 inches (Geometry) WILL GIVE BRAINY) Mark each figure to indicate the given information. A wave has a frequency of 50 Hz and a wavelength of 10 m. What is the speed of the wave? Select the correct answer.Each side of a square is(st5) units. Which expression can be used to represent the area of the square?22 - 50 - 10I2 50 + 102 100 - 2522 - 10x + 25