-
Notifications
You must be signed in to change notification settings - Fork 0
/
Console.py
executable file
·55 lines (43 loc) · 1.54 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
import os
class Console:
@staticmethod
def read_str(message: str) -> int:
result = str(input(message))
while not all(i.isalnum() or i.isspace() for i in result):
print(f"Error!!!. El caracter ingresado '{result}' no son letras")
result = str(input(message))
return result
@staticmethod
def read_int(message: str) -> int:
result = input(message)
while not result.isnumeric():
print(f"Error!!!. El caracter ingresado '{result}' no es un número")
result = input(message)
return int(result)
@staticmethod
def read_number(message: str) -> float:
result = input(message)
while not Console.__is_float(result):
print(f"Error!!!. El caracter ingresado '{result}' no es un número")
result = input(message)
return result
@staticmethod
def is_yes(message: str) -> bool:
result = str(input(message))
while not result == "" and not result == "y" and not result == "n":
print(f"Error!!!. El caracter ingresado '{result}' es y o n")
result = str(input(message))
return result == "y" or result == ""
def __is_float(n) -> bool:
try:
float(n)
except ValueError:
return False
return True
@staticmethod
def clean_screen():
os.system("clear" if os.name == "posix" else "cls")
# Console.read_str("sjY/n): ")
# print(Console.is_yes("Si o no??? "))
# print("1".isalnum())
# print(len(" "))