day 7 - didn't like it
This commit is contained in:
30
006/task.py
30
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()
|
||||
# while not at_goal():
|
||||
# if not wall_on_right():
|
||||
# turn_right()
|
||||
# move()
|
||||
# elif not wall_in_front():
|
||||
# move()
|
||||
# else:
|
||||
# turn_left()
|
||||
41
007/task.py
Normal file
41
007/task.py
Normal file
@ -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!")
|
||||
Reference in New Issue
Block a user