day 14 + cleanup

This commit is contained in:
Tanguy Deleplanque
2025-06-20 11:45:12 +02:00
parent 07f37394d9
commit 7f9b263baa
6 changed files with 349 additions and 1 deletions

41
012/task.py Normal file
View File

@ -0,0 +1,41 @@
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)