File tree 4 files changed +56
-0
lines changed
4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
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 ("\n choose 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\n Guess again.\n " )
37
+ guessfn ()
38
+ elif guess <= answer - 2 :
39
+ attempts -= 1
40
+ print ("Too low.\n Guess again.\n " )
41
+ guessfn ()
42
+ else :
43
+ attempts -= 1
44
+ print ("Too high.\n Guess 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 ()
Original file line number Diff line number Diff line change
1
+ logo = """
2
+
3
+ ▒█▀▀█ █░░█ █▀▀ █▀▀ █▀▀ ░▀░ ▀▀█▀▀
4
+ ▒█░▄▄ █░░█ █▀▀ ▀▀█ ▀▀█ ▀█▀ ░░█░░
5
+ ▒█▄▄█ ░▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ░░▀░░
6
+ """
You can’t perform that action at this time.
0 commit comments