-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSOB #28.py
38 lines (28 loc) · 1.18 KB
/
SOB #28.py
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
33
34
35
36
37
38
#import used to gain access to code in another module
import random
def guess_number():
play_again = True
while play_again:
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
print("Welcome to the Number Guessing Game!")
print("I have selected a number between 1 and 100. Try to guess it.")
attempts = 0
while True:
# Get the player's guess
guess = int(input("Enter your guess: "))
# Increment the attempts counter
attempts += 1
# Check if the guess is correct
if guess == secret_number:
print(f"Congratulations! You guessed the number in, {attempts} attempts.")
break
elif guess < secret_number:
print("Too low. Try again.")
else:
print("Too high. Try again.")
# Ask the player if they want to play again
play_again_input = input("Do you want to play again? (yes/no): ").lower()
play_again = play_again_input == 'yes'
if __name__ == "__main__":
guess_number()