-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (42 loc) · 1.89 KB
/
main.py
File metadata and controls
52 lines (42 loc) · 1.89 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
# Number Guessing Game Objectives:-
# Include an ASCII art logo.
# Allow the player to submit a guess for a number between 1 and 100.
# Check user's guess against actual answer. Print "Too high." or "Too low." depending on the user's answer.
# If they got the answer correct, show the actual answer to the player.
# Track the number of turns remaining.
# If they run out of turns, provide feedback to the player.
# Include two different difficulty levels (e.g., 10 guesses in easy mode, only 5 guesses in hard mode).
import os
import random
from os import path
from art import logo
from numberList import numbers
from time import sleep
def guess_the_number():
print('\n', logo, "\nWelcome to the Number Guessing Game!\nI'm thinking of a number between 1 and 100.")
difficulty = input("\nChoose a difficulty. Type 'easy' or 'hard': ")
choosen_number = random.choice(numbers)
if difficulty.lower() == 'easy':
number_of_guesses = 10
elif difficulty.lower() == 'hard':
number_of_guesses = 5
while number_of_guesses != 0:
guess = int(input(
f"\nYou have {number_of_guesses} attempts remaining to guess the number.\nMake a guess: "))
if guess == int(choosen_number):
print(f"\nYou got it! The answer was {choosen_number}.")
break
number_of_guesses -= 1
if number_of_guesses == 0:
print(
f"You've run out of guesses, you lose.\nThe answer was {choosen_number}.")
break
elif guess > int(choosen_number):
print("\nToo High.\nGuess again.")
elif guess < int(choosen_number):
print("\nToo Low.\nGuess again.")
# for playing first time by directly running code.
guess_the_number()
if input("\nDo you want to play again?, Type 'y' for Yes, 'n' for No: ").lower() == 'y':
os.system('cls') # clearing the screen of console
guess_the_number()