Loading...
Loading...
Build a number guessing game using everything you have learned
Build a complete number guessing game! You'll use variables, input, conditionals, loops, random numbers, and functions — all the concepts from this course.
The starter code has the basic structure. Complete the missing parts!
import random
secret = random.randint(1, 100)
tries = 0
# Your code here!
# Use a while loop that keeps asking for guesses
# Compare each guess to the secret number
# Give feedback: too low, too high, or correctYour guess: 50
Too high! Try again.
Your guess: 25
Too low! Try again.
Your guess: 37
Too high! Try again.
Your guess: 31
Correct! You got it in 4 tries!import random
secret = random.randint(1, 100)
tries = 0
print("I'm thinking of a number between 1 and 100...")
while True:
guess = int(input("Your guess: "))
tries += 1
if guess < secret:
print("Too low! Try again.")
elif guess > secret:
print("Too high! Try again.")
else:
print(f"Correct! You got it in {tries} tries!")
break