87.7k views
8 votes
Write a program that has a user guess a secret number between 1 and 10. Store the secret number in a variable called secretNumber and allow the user to continually input numbers until they correctly guess what secretNumber is. Complete the method guessMyNumber that uses a while loop to ask the user for their guess and compares it againist secretNumber. For example, if secretNumber was 6, an example run of the program may look like this:_______.

User Mechlar
by
7.9k points

1 Answer

7 votes

Final answer:

The student is tasked with creating a number guessing game in Computers and Technology where the user attempts to guess a secret number until the correct number is guessed, using a while loop for the logic.

Step-by-step explanation:

The question requires the creation of a simple number guessing game program, which falls under the subject of Computers and Technology for the High School level. The program should allow a user to guess a secret number between 1 and 10 until they get it right. Here's a basic outline of the program using a while loop:

secretNumber = 6 # this is the secret number
while True:
guess = int(input('Guess my number (between 1 and 10): '))
if guess == secretNumber:
print('Congratulations! You guessed the right number.')
break
else:
print('Try again!')
In this program, secretNumber is set to 6 (as per the example), and the while loop keeps prompting the user to guess until the correct number is entered. Upon the correct guess, a congratulatory message is displayed, and the loop is terminated with a break statement. If the guess is incorrect, the user is prompted to try again.
User Mwilcox
by
8.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.