forked from Supercip971/convertisseur-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.py
More file actions
39 lines (28 loc) · 1.14 KB
/
console.py
File metadata and controls
39 lines (28 loc) · 1.14 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
import converter
import sys
def console_error_check(val: int, inputed_val: str, action: str):
if val == None:
print("erreur: l'action'", action,
"' ne peut pas utiliser la valeur '", inputed_val, "'")
sys.exit()
input_message = "tappez: 'x' pour hexadécimal, 'd' pour décimal, 'b' pour binaire, 'q' pour quitter: (x/d/b/q):"
def console_run():
while True:
action = input(input_message)
if not action in "xdbq":
print("action invalide:", action)
continue
if action == 'q':
exit()
val = input("entez une valeur: ")
converted_val = 0
if action == 'b':
converted_val = converter.val_from_bin(val)
elif action == 'x':
converted_val = converter.val_from_hex(val)
else:
converted_val = converter.val_from_dec(val)
console_error_check(converted_val, val, action)
print("valeur décimale:", converter.val_to_dec(converted_val))
print("valeur hexadécimale:", converter.val_to_hex(converted_val))
print("valeur binaire:", converter.val_to_bin(converted_val))