41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
import random
|
|
|
|
def play_attempt(number_to_find):
|
|
|
|
guess = int(input("Make a guess: "))
|
|
|
|
if guess > number_to_find:
|
|
print("Number is lower")
|
|
return(True)
|
|
elif guess < number_to_find:
|
|
print("Number is higher")
|
|
return(True)
|
|
else:
|
|
print("You won ! - Number to find was {number_to_find}")
|
|
return(False)
|
|
|
|
def play_game(level):
|
|
if level == "easy":
|
|
attempts_remaining = 10
|
|
else:
|
|
attempts_remaining = 5
|
|
|
|
number_to_find = random.randint(1, 100)
|
|
|
|
for attemps in range(attempts_remaining):
|
|
print(f"Attempts remainging: {attempts_remaining}")
|
|
b_keep_going = play_attempt(number_to_find)
|
|
if b_keep_going == False:
|
|
break
|
|
attempts_remaining -= 1
|
|
|
|
if attempts_remaining == 0:
|
|
print(f"You lost! - Number to find was {number_to_find}")
|
|
return
|
|
|
|
|
|
|
|
print("I'm thinking of a number between 1 and 100.")
|
|
level = input("Chose a difficulty: 'easy' or 'hard':")
|
|
|
|
play_game(level) |