-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
93 lines (78 loc) · 2.47 KB
/
ui.py
File metadata and controls
93 lines (78 loc) · 2.47 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# ui.py
from typing import Tuple
from db import MySakilaConnection
import setting as se
import sys
def display_menu():
"""
Displays the search scenario selection menu.
"""
print('Select a search scenario:')
print('\n'.join(se.MENU_ITEMS))
def get_user_choice() -> int:
"""
Gets the user's selection.
"""
while True:
choice = input(f"Enter the scenario number. (1-{len(se.SCENARIO_SET)}): ").strip()
if choice in se.SCENARIO_SET:
return choice
print(f"Error: Please select a number from 1 to {len(se.SCENARIO_SET)}.")
def get_rating() -> int:
"""
Gets the rating from the user.
"""
while True:
try:
rating = int(input(f'''Enter the rating.:
{se.RATING_TEXT}
'''))
if not 1 <= rating <= se.RATING_LEN:
print(f"Error: Please enter a numerical rating (1 - {se.RATING_LEN}).")
else:
return rating
except ValueError:
print("Error: Please enter the rating in numeric format.")
def get_keyword() -> str:
"""
Gets the keyword from the user.
"""
keyword = input("Enter the keyword: ").strip()
if not keyword:
print("Error: The keyword cannot be empty!")
else:
return keyword
def get_genre_and_year() -> Tuple[str, int]:
"""
Gets the genre and year from the user.
"""
while True:
genre = input("Enter the genre: ").strip()
if not genre:
print("Error: The genre cannot be empty!")
continue
try:
year = int(input("Enter the year: "))
if year <= 0:
print("Error: The year must be a positive number.")
else:
return genre, year
except ValueError:
print("Error: Please enter the year in numeric format.")
def get_actor_and_year() -> Tuple[str, int]:
"""
Gets the actor's name and year from the user.
"""
while True:
actor = input("Enter the actor's name: ").replace(" ", "")
if not actor:
print("Error: The name cannot be empty!")
continue
try:
year = int(input("Enter the year: "))
if year <= 0:
print("Error: The year must be a positive number.")
else:
return actor, year
except ValueError:
print("Error: Please enter the year in numeric format.")