79.5k views
17 votes
Write a program that has a user guess a secret number between 1 and 10. Store the secret number in a variable called secret Number and allow the user to continually input numbers until they correctly guess what secretNumber is. For example, if secretNumber was 6, an example run of the program may look like this:

User Dkruchok
by
4.9k points

1 Answer

1 vote

Answer:

The program in Python is as follows:

import random

secretNum = random.randint(1,10)

userNum = int(input("Take a guess: "))

while(userNum != secretNum):

print("Incorrect Guess")

userNum = int(input("Take a guess: "))

print("You guessed right")

Step-by-step explanation:

This imports the random module

import random

This generates a secrete number

secretNum = random.randint(1,10)

This prompts the user to take a guess

userNum = int(input("Take a guess: "))

This loop is repeated until the user guess right

while(userNum != secretNum):

print("Incorrect Guess")

userNum = int(input("Take a guess: "))

This is executed when the user guesses right

print("You guessed right")

User Jiminikiz
by
5.5k points