Repository navigation
Expand file tree
/
Copy pathGuess_The_Number.py
More file actions
69 lines (54 loc) · 1.7 KB
/
Copy pathGuess_The_Number.py
File metadata and controls
69 lines (54 loc) · 1.7 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# DAY-12
import random
from replit import clear
from art import logo
print(logo)
def game():
answer = random.randint(1, 100)
print("Welcome to the Number guessing Game:")
print("Think of a number between 1 to 100: ")
difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ")
def easy():
attempt = 10
while attempt != 0:
print(
f"You have {attempt} attempts remaining to guess the number.")
number = int(input("Make a guess: "))
if number > answer:
print("Too high.")
print("Guess again.")
attempt -= 1
elif number < answer:
print("Too Low.")
print("Guess again.")
attempt -= 1
else:
print(f"You got it! The asnwer was {answer}.")
break
def hard():
attempt = 5
while attempt != 0:
print(
f"You have {attempt} attempts remaining to guess the number.")
number = int(input("Make a guess: "))
if number > answer:
print("Too high.")
print("Guess again.")
attempt -= 1
elif number < answer:
print("Too Low.")
print("Guess again.")
attempt -= 1
else:
print(f"You got it! The asnwer was {answer}.")
break
if difficulty == 'easy':
easy()
else:
hard()
play = input("Do you want to play this game? Type 'y' or 'n': ")
if play == 'y':
clear()
game()
else:
clear()