-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessing
More file actions
32 lines (25 loc) · 935 Bytes
/
guessing
File metadata and controls
32 lines (25 loc) · 935 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
28
29
30
31
32
import random
def guessing_game():
secret_number = random.randint(1, 100) # Generates a random number between 1 and 100
attempts = 0
print("let's play a guessing game!")
print("think of a number between 1 and 100. try to get what i'm thinking of!")
while True:
guess = int(input("Your guess: "))
attempts += 1
if guess < secret_number:
print("nope, too low!")
elif guess > secret_number:
print("yikes, too high!")
else:
print(f"good job! you got {secret_number} in {attempts} attempts.")
break
play_again = input("do you want to play again? (yes/no): ").strip().lower()
return play_again == "yes"
if __name__ == "__main__":
while True:
if not guessing_game():
print("thanks for playing! :D")
break
if __name__ == "__main__":
guessing_game()