generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
helpers.py
70 lines (58 loc) · 1.47 KB
/
helpers.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
64
65
66
67
68
69
70
from os import system, name
from time import sleep
from datetime import datetime
from termcolor import cprint
now = datetime.now()
current_hour = int(now.strftime("%H"))
def ask_yes_no(question):
"""
Asks the user for input for a Yes/No Question
and returns a boolean
Args:
question: The question to ask
"""
yes = ["yes", "y"]
no = ["no", "n"]
print(f"\n{question}")
print(f"\n[Y/n]\n")
while True:
choice = input().lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print("[Y]es or [N]o")
continue
def is_quit(response):
"""
Checks if the user's response
was to quit the game, if so ask to confirm.
Returns True if user wants to quit,
otherwise returns False.
"""
if response.lower() in ["q", "quit"]:
if ask_yes_no("Would you like to return to the Main Menu?\n"):
return True
else:
return False
else:
return False
def ask_any_key():
"""
Ask the user to press any key to return to main menu
"""
cprint("Press any key to return to Main Menu.", "white", "on_blue")
input()
return
# Source: https://stackoverflow.com/questions/2084508/clear-terminal-in-python
def clear():
"""
Clears the Terminal Window
"""
# for Windows
if name == "nt":
_ = system("cls")
# for macOS/Linux
else:
_ = system("clear")