Skip to content

Commit cd14d46

Browse files
authored
day 12 Number Guessing Game
1 parent 2c3f7a1 commit cd14d46

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

Day12-Guess/Day 12 Project-guess.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from art import logo
2+
import random
3+
print("\033[36m",logo,"\033[0m")
4+
5+
answer = random.randint(10,91)
6+
attempts = 0
7+
8+
def choose():
9+
global attempts
10+
difficulty = input("\nchoose difficulty. Type 'easy' or 'hard': \n")
11+
if difficulty == 'easy':
12+
attempts = 10
13+
guessfn()
14+
elif difficulty == 'hard':
15+
attempts = 5
16+
guessfn()
17+
else:
18+
print("Enter valid word")
19+
choose()
20+
21+
def guessfn():
22+
global attempts
23+
global answer
24+
if attempts == 0:
25+
print("\033[32mYou've run out of guesses, You lose.\033[0m")
26+
while attempts:
27+
print(f"You have \033[31m{attempts}\033[0m attempts remaining to guess the number.")
28+
guess = int(input("Make a guess: "))
29+
if guess == answer:
30+
attempts = 0
31+
print("\033[32m")
32+
print(f"You got it!. The answer was {answer}")
33+
print("\033[0m")
34+
elif (answer - 2) < guess < (answer + 2):
35+
attempts -= 1
36+
print("\033[32mToo close.\033[0m\nGuess again.\n")
37+
guessfn()
38+
elif guess <= answer - 2:
39+
attempts -= 1
40+
print("Too low.\nGuess again.\n")
41+
guessfn()
42+
else:
43+
attempts -= 1
44+
print("Too high.\nGuess again.\n")
45+
guessfn()
46+
47+
print("Welcome to the Number Geussing Game!")
48+
print("I'm thinking of a number between 1 and 100.")
49+
# print(answer)
50+
choose()

Day12-Guess/art.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
logo = """
2+
3+
▒█▀▀█ █░░█ █▀▀ █▀▀ █▀▀   ░▀░ ▀▀█▀▀
4+
▒█░▄▄ █░░█ █▀▀ ▀▀█ ▀▀█   ▀█▀ ░░█░░
5+
▒█▄▄█ ░▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀   ▀▀▀ ░░▀░░
6+
"""

Day12-Guess/guess.gif

2.44 MB
Loading

Day12-Guess/guess.mp4

3.67 MB
Binary file not shown.

0 commit comments

Comments
 (0)