-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber_guesser.py
More file actions
27 lines (21 loc) · 814 Bytes
/
number_guesser.py
File metadata and controls
27 lines (21 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import random
while True:
target_number = random.randint(1, 10)
print("Welcome to the Number Guessing Game!")
print("I have chosen a number between 1 and 10. Try to guess it!")
guesses = 0
while True:
guess = int(input("Enter your guess: "))
guesses += 1
if guess < target_number:
print("Too low! Try again.")
elif guess > target_number:
print("Too high! Try again.")
else:
print("Correct, you win! Congrats.")
print(f"It took you {guesses} guesses to get the correct number.")
break
start_again = input("Would you like to play again? (Yes/No) ").lower()
if start_again == "no":
print("Thanks for playing! Goodbye.")
break