From 07f37394d9905d7346201b46f322564595b7a5d4 Mon Sep 17 00:00:00 2001 From: Tanguy Deleplanque Date: Thu, 19 Jun 2025 14:10:40 +0200 Subject: [PATCH] day 12 --- 12/task.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 12/task.py diff --git a/12/task.py b/12/task.py new file mode 100644 index 0000000..fdd525f --- /dev/null +++ b/12/task.py @@ -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) \ No newline at end of file