-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsole.py
59 lines (51 loc) · 1.56 KB
/
console.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
import os
from colorama import Fore, Style
clearConsole = lambda: os.system('cls' if os.name in ('nt', 'dos') else 'clear')
def succes(s):
return Fore.GREEN + s + Style.RESET_ALL
def question(s):
return Style.BRIGHT + s + Style.RESET_ALL
def info(s):
return Style.DIM + s + Style.RESET_ALL
def warning(s):
return Fore.YELLOW + s + Style.RESET_ALL
def error(s):
return Fore.RED + s + Style.RESET_ALL
def input_yesno(q):
while True:
answer = input(question(f"{q} y/n: ")).lower()
if answer == "y" or answer == "yes":
return "y"
if answer == "n" or answer == "no":
return "n"
def input_currency(prompt = "How much money do you want to deposit: "):
full = 0
cents = 0
isValid = False
while not isValid:
raw_money = input(question(prompt))
if "." in raw_money and len(raw_money.split(".")) == 2:
full, cents = raw_money.split(".")
try:
full = int(full)
if len(cents) == 1:
cents = int(cents) * 10
elif len(cents) == 2:
cents = int(cents)
else:
raise Exception
except:
pass
else:
if full >= 0 and cents >= 0:
isValid = True
else:
try:
full = int(raw_money)
except:
pass
else:
if full >= 0:
isValid = True
money = full * 100 + cents
return money