-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
52 lines (44 loc) · 1.46 KB
/
project.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# NUMBER GUESSING GAME
from project_art import logo
from replit import clear
import random
def number_generator():
return random.randint(1, 100)
def play_game():
global number
for _ in range(rounds):
guess = int(input("Guess a number: "))
if guess == number:
print(f"You got it. The actual answer is {number}")
return
elif guess > number:
print("Too high! Try again.")
elif guess < number:
print("Too low! Try again.")
print("You've run out of guesses. You lose!")
return False
while True:
clear()
print(logo)
print("Welcome to Number Guessing Game!")
# Gera um novo número aleatório para cada iteração do loop
number = number_generator()
print("I am thinking in a number between 1 and 100.")
difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ").lower().strip()
if difficulty == "easy":
rounds = 10
elif difficulty == "hard":
rounds = 5
else:
print("Invalid input. Please choose 'easy' or 'hard'.")
continue
if play_game(): # Se True
play_again = input("Do you want to play again? Type 'yes' or 'no': ")
if play_again.lower() != 'yes':
print("Goodbye!")
break
else: # Se False
play_again = input("Do you want to play again? Type 'yes' or 'no': ")
if play_again.lower() != 'yes':
print("Goodbye!")
break