-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuess_the_number.py
77 lines (58 loc) · 3.83 KB
/
Guess_the_number.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import random
import os
logo = '''
░██████╗░██╗░░░██╗███████╗░██████╗░██████╗ ████████╗██╗░░██╗███████╗
██╔════╝░██║░░░██║██╔════╝██╔════╝██╔════╝ ╚══██╔══╝██║░░██║██╔════╝
██║░░██╗░██║░░░██║█████╗░░╚█████╗░╚█████╗░ ░░░██║░░░███████║█████╗░░
██║░░╚██╗██║░░░██║██╔══╝░░░╚═══██╗░╚═══██╗ ░░░██║░░░██╔══██║██╔══╝░░
╚██████╔╝╚██████╔╝███████╗██████╔╝██████╔╝ ░░░██║░░░██║░░██║███████╗
░╚═════╝░░╚═════╝░╚══════╝╚═════╝░╚═════╝░ ░░░╚═╝░░░╚═╝░░╚═╝╚══════╝
███╗░░██╗██╗░░░██╗███╗░░░███╗██████╗░███████╗██████╗░
████╗░██║██║░░░██║████╗░████║██╔══██╗██╔════╝██╔══██╗
██╔██╗██║██║░░░██║██╔████╔██║██████╦╝█████╗░░██████╔╝
██║╚████║██║░░░██║██║╚██╔╝██║██╔══██╗██╔══╝░░██╔══██╗
██║░╚███║╚██████╔╝██║░╚═╝░██║██████╦╝███████╗██║░░██║
╚═╝░░╚══╝░╚═════╝░╚═╝░░░░░╚═╝╚═════╝░╚══════╝╚═╝░░╚═╝
'''
easy_difficulty = 10
hard_difficulty = 5
def check(guess, answer, turns):
"""Checks the answer, returns the number of turns left."""
if guess > answer:
print("Too high!")
return turns - 1
elif guess < answer:
print("Too low!")
return turns - 1
else:
print(f"You got it! The answer was {answer}")
os.system("pause")
def difficulty():
asking_user = True
while asking_user:
user_choice = input("Choose a difficulty 'easy' or 'hard': \n").lower()
if user_choice == "easy":
asking_user = False
return easy_difficulty
elif user_choice == "hard":
asking_user = False
return hard_difficulty
else:
print("Invalid input, type again!")
print(logo)
def game():
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
answer = random.randint(1, 100)
turns = difficulty()
guess = 0
while guess != answer:
print(f"You have {turns} attempts to guess the number.")
guess = int(input("Make a guess: "))
turns = check(guess, answer, turns)
if turns == 0:
print("You run out of guesses, you lose!")
print(f"The answer was: {answer}")
os.system("pause")
return
game()