-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathguess_the_animal.py
executable file
·44 lines (33 loc) · 1.07 KB
/
guess_the_animal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
Play a game of 'guess the animal', with hints.
"""
correct_answer = 'african swallow'
hints = ['weighs five ounces',
'beats its wings 43 times per second',
'is not migratory',
'has dorsal guiding feathers',
'can carry a coconut',
'is not European']
print("I'm thinking of an animal.")
for h in hints:
# Get the guess and 'clean' it.
print('Hint: It {}.'.format(h))
guess = input("What is it (or type 'q' to quit)? ")
guess = guess.strip().lower()
# If the guess is empty, keep asking.
while guess == '':
guess = input("Enter the name of an animal (or 'q' to quit): ")
guess = guess.strip().lower()
# Deal with the 'quit' option first.
if guess == 'q':
print('So you give up, eh?')
break
# Check the guess and stop if correct.
if guess == correct_answer:
print('Correct!')
break
else:
print("No, that's not it.")
# A final message revealing (or confirming) the answer.
print('It was the {}.'.format(correct_answer))