-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathguess_that_movie_solution.py
63 lines (46 loc) · 1.36 KB
/
guess_that_movie_solution.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import movies
def game_menu(hints):
print("Type your guess, or")
if len(hints) == 0:
print("g - give up, tell me the answer")
else:
print("h - get a hint")
print("q - quit")
return input()
def movie_intro(movie_data):
print("Guess the movie!")
print("Actors: {}".format(movie_data['Actors']))
def handle_response(hints, movie_data, resp):
# Status codes:
# 0 nothing interesting happened
# 1 need a new guess
# 2 quit the game
status = 0
if resp == "h":
h = hints.pop()
print("{}: {}".format(h, movie_data[h]))
elif resp == "g":
print("\nThe moive was {}\n".format(movie_data['Title']))
status = 1
elif resp == "q":
status = 2
elif resp.lower() == movie_data['Title'].lower():
print("\nYou got it! The movie is {}\n".format(movie_data['Title']))
status = 1
else:
print("Sorry, try again!")
return status
def hint_array():
return ["Plot", "Director", "Year"]
def guessing_game():
hints = None
status = 1
while status != 2:
if status == 1:
movie_data = movies.random_movie_data()
hints = hint_array()
movie_intro(movie_data)
resp = game_menu(hints)
status = handle_response(hints, movie_data, resp)
print("\nThanks for playing!\n")
guessing_game()