From 8c0b19bb6cc7a2ce3eebe4d8b6a1fc36f3f22d2d Mon Sep 17 00:00:00 2001 From: Tanguy Deleplanque Date: Sun, 15 Jun 2025 00:10:07 +0200 Subject: [PATCH] day 7 - didn't like it --- 006/task.py | 30 +++++++++++++++--------------- 007/task.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 007/task.py diff --git a/006/task.py b/006/task.py index 3eddcf5..1aa4e2c 100644 --- a/006/task.py +++ b/006/task.py @@ -10,20 +10,20 @@ # Either the test front_is_clear() or wall_in_front(), right_is_clear() or wall_on_right(), and at_goal(). # How to use a while loop and if/elif/else statements. # It might be useful to know how to use the negation of a test (not in Python). -def turn_right(): - turn_left() - turn_left() - turn_left() +# def turn_right(): +# turn_left() +# turn_left() +# turn_left() -while front_is_clear(): - move() -turn_left() +# while front_is_clear(): +# move() +# turn_left() -while not at_goal(): - if not wall_on_right(): - turn_right() - move() - elif not wall_in_front(): - move() - else: - turn_left() \ No newline at end of file +# while not at_goal(): +# if not wall_on_right(): +# turn_right() +# move() +# elif not wall_in_front(): +# move() +# else: +# turn_left() \ No newline at end of file diff --git a/007/task.py b/007/task.py new file mode 100644 index 0000000..df4f9d0 --- /dev/null +++ b/007/task.py @@ -0,0 +1,41 @@ +import random + +word_list = ["aardvark", "baboon", "camel"] + +chosen_word = random.choice(word_list) +print(chosen_word) + +placeholder = "_" * len(chosen_word) +print(placeholder) + +found_letters = [] +lives = 6 + +display = placeholder + +while "_" in display and lives > 0: + guess = input("Select a letter:\n").lower() + + display = "" + + found_a_letter = False + + for letter in chosen_word: + if letter == guess: + display += letter + found_a_letter = True + found_letters.append(letter) + elif letter in found_letters: + display += letter + else: + display += "_" + + if found_a_letter == False: + lives -= 1 + + print(display) + +if lives == 0: + print("Game over!") +else: + print("You won!") \ No newline at end of file