-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber
62 lines (37 loc) · 1.45 KB
/
number
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
#Number Guessing Game Objectives:
# Include an ASCII art logo.
from art import logo
print(logo)
print("Welcome to the number guessing game.")
print("I'm thinking a number between 1 to 100.")
# Include two different difficulty levels (e.g., 10 guesses in easy mode, only 5 guesses in hard mode).
hardness = input("Choose a difficulty, easy or hard: ").lower()
if hardness == "easy":
play_time = 10
elif hardness == "hard":
play_time = 5
else:
print("Invaild input, please type 'easy' or 'hard'")
play_time=0
# Allow the player to submit a guess for a number between 1 and 100.
import random
NUMBER = random.choice(range(1,101))
def game(play_time):
for _ in range(play_time):
# Track the number of turns remaining.
print(f"You have {play_time} attempts to make a guess.")
if play_time > 0:
guess = int(input("Make a guess: "))
# Check user's guess against actual answer. Print "Too high." or "Too low." depending on the user's answer.
if guess > NUMBER:
print("Too high.")
elif guess < NUMBER:
print("Too low.")
# If they got the answer correct, show the actual answer to the player.
elif guess == NUMBER:
print(f"You have it. The correct answer is {guess}")
play_time -= 1
# If they run out of turns, provide feedback to the player.
if play_time == 0:
print(f"You are out of move, the correct answer is {NUMBER} ")
game(play_time)