-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.py
More file actions
57 lines (47 loc) · 2.38 KB
/
Code.py
File metadata and controls
57 lines (47 loc) · 2.38 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
class PiggyBank:
def __init__(self):
self.history = []
self.target = 0.0
self.saved = 0.0
self.lang = "en"
self.translations = {
"it": {"title": "Salvadanaio Digitale", "target": "Target Totale", "current": "Budget Attuale", "missing": "Mancano", "saved": "Accumulato", "history": "Cronologia"},
"en": {"title": "Digital Piggy Bank", "target": "Total Target", "current": "Current Budget", "missing": "Remaining", "saved": "Saved", "history": "History Log"},
"fr": {"title": "Ma Tirelire", "target": "Cible Totale", "current": "Budget Actuel", "missing": "Restant", "saved": "Accumulé", "history": "Historique"},
"de": {"title": "Sparschwein", "target": "Gesamtziel", "current": "Aktuelles Budget", "missing": "Fehlend", "saved": "Gespart", "history": "Verlauf"},
"sp": {"title": "Mi Hucha Digital", "target": "Meta Total", "current": "Ahorro Actual", "missing": "Faltante", "saved": "Acumulado", "history": "Historial"}
}
def clear_screen(self):
os.system('cls' if os.name == 'nt' else 'clear')
def display(self):
self.clear_screen()
t = self.translations[self.lang]
missing = max(0, self.target - self.saved)
percent = (self.saved / self.target * 100) if self.target > 0 else 0
print(f"{'='*40}")
print(f"{t['title'].center(40)}")
print(f"{'='*40}")
print(f"{t['missing']}: {missing:.2f}")
print(f"{t['saved']}: {percent:.1f}%")
print(f"{'-'*40}")
print(f"{t['history']}:")
for entry in reversed(self.history[-5:]):
print(f" > {entry:.2f}")
print(f"{'='*40}")
def run(self):
self.lang = input("Language (it/en/fr/de/sp): ").lower()
if self.lang not in self.translations: self.lang = "en"
self.target = float(input(f"{self.translations[self.lang]['target']}: "))
while True:
try:
val = input(f"{self.translations[self.lang]['current']} (or 'q' to quit): ")
if val.lower() == 'q': break
self.saved = float(val)
self.history.append(self.saved)
self.display()
except ValueError:
print("Invalid input!")
if __name__ == "__main__":
bank = PiggyBank()
bank.run()