-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.py
42 lines (36 loc) · 1.11 KB
/
helper.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
import os
def print_sep(sep=""):
print(
f"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n{sep}"
)
def clear_terminal():
os.system("cls" if os.name == "nt" else "clear")
def assert_type(
value,
type_=str,
message="Enter value: ",
error_message="invalid input",
take_value=False,
key=lambda x: x,
):
while True:
try:
if take_value and not value:
value = type_(input(message))
else:
value = type_(value)
if not key(value):
raise ValueError
else:
clear_terminal()
break
except ValueError:
value = None
print(error_message)
choice = input("Do you want to try again? (y/n): ").lower()
if choice == "n":
clear_terminal()
return False
elif choice == "y":
pass
return value