-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_entry.py
More file actions
35 lines (29 loc) · 1.11 KB
/
Copy pathdata_entry.py
File metadata and controls
35 lines (29 loc) · 1.11 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
from datetime import datetime
date_format = "%d-%m-%Y"
CATEGORIES = {"I": "Income", "E": "Expense"}
def get_date(prompt, allow_default=False):
date_str = input(prompt)
if allow_default and not date_str:
return datetime.today().strftime(date_format)
try:
valid_date = datetime.strptime(date_str,date_format)
return valid_date.strftime(date_format)
except ValueError:
print("Invalid Date format. Enter the date in dd-mm-YYYY format ⚠️")
return get_date(prompt,allow_default)
def get_amount():
try:
amount = float(input("Enter the amount: "))
if amount <= 0:
raise ValueError("Amount must be a non-negative non-zero value.")
return amount
except ValueError as e:
print(e)
return get_amount()
def get_category():
category = input("Enter the category ('I' for Income or 'E' for Expense): ").upper()
if category in CATEGORIES:
return CATEGORIES[category]
print("Invalid Category. Please enter 'I' for Income or 'E' for Expense .")
def get_description():
return input("Enter a description: ")