1 # the following code is an expense report to help the user keep tack of expenses : 2 import datetime 3 #initilising an empty dict to store any expenses 4 expenses = {} 5 expenses_dict= {"Food": [], "Transport": [], "Entertainment": [], "Work": []} 6 7 8 9 10 11 v 12 v 13 14 15 v 16 17 18 19 20 21 v 22 23 24 25 def add_expense(): V print("Please add an Expense: ") item_name = input("Item Name: ") category =input("Category (Food/Transport/Entertainment/work): ") while True: try: } 26 27 28 ក AI (~} Python #grabbing the current date and time: timestamp = datetime.datetime.now() #storing the expense in the dict expenses[timestamp] ={ "item_name": item_name, "category": category, "amount": amount amount = float(input("Amount: £")) break except ValueError: print("Invalid input. please enter a valid amount.") print("Expense added\n") def calculate_total(): batal

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

im really stuck on creating a few simple  replit tests (unit tests )for the following code in the pictures below . may you please help me with this. 

main.py
1 # the following code is an expense report to help the user keep tack of expenses :
2 import datetime
3 #initilising an empty dict to store any expenses
4 expenses = {}
5 expenses_dict= {"Food": [], "Transport": [], "Entertainment": [], "Work": []}
6 def add_expense():
V
7
8
9
10
11 v
12v
13
14
15 v
16
print("Please add an Expense: ")
item_name = input("Item Name: ")
category=input("Category (Food/Transport/Entertainment/work): ")
while True:
try:
amount = float(input("Amount: f"))
break
except ValueError:
print("Invalid input. please enter a valid amount.")
17
18
19
20
21 v
22
23
24
25
26
27
28 def calculate_total():
V
20
AI {} Python
}
#grabbing the current date and time:
timestamp= datetime.datetime.now()
#storing the expense in the dict
expenses [timestamp] = {
"item_name": item_name,
"category": category,
"amount": amount
print("Expense added\n")
batal
Transcribed Image Text:main.py 1 # the following code is an expense report to help the user keep tack of expenses : 2 import datetime 3 #initilising an empty dict to store any expenses 4 expenses = {} 5 expenses_dict= {"Food": [], "Transport": [], "Entertainment": [], "Work": []} 6 def add_expense(): V 7 8 9 10 11 v 12v 13 14 15 v 16 print("Please add an Expense: ") item_name = input("Item Name: ") category=input("Category (Food/Transport/Entertainment/work): ") while True: try: amount = float(input("Amount: f")) break except ValueError: print("Invalid input. please enter a valid amount.") 17 18 19 20 21 v 22 23 24 25 26 27 28 def calculate_total(): V 20 AI {} Python } #grabbing the current date and time: timestamp= datetime.datetime.now() #storing the expense in the dict expenses [timestamp] = { "item_name": item_name, "category": category, "amount": amount print("Expense added\n") batal
main.py x test.py x +
main.py
PI LILL experive ATE
27
28 def calculate_total():
29
30
47
48 ✓
49
total = sum(expense["amount"]for expense in expenses.values())
print (f"\nTotal Expenses : £{total:.2f}\n")
31
32 def generate_report():
33
34 v
35
36
37 def main():
38 v
39
40
41
42
43
44
45
46 v
print("\nexpense Report:\n ")
for timestamp, expense in expenses.items():
print(f"{timestamp} - {expense['item_name']} ({expense['category']}): £{expense['amount']:.2f}")
while True:
50 ✓
51
52 v
53
54
AI () Python
print("Expense Tracker Menu: ")
print("1: Add an Expense")
print("2: Calculate Total ")
print("3: Generate Report")
print("4: Exit")
choice = input ("Enter a choice (1-4): ")
if choice == "1":
add_expense()
elif choice == "2":
calculate_total()
elif choice == "3":
generate_report()
elif choice == '4':
print("leaving Expense tracker.")
break
Transcribed Image Text:main.py x test.py x + main.py PI LILL experive ATE 27 28 def calculate_total(): 29 30 47 48 ✓ 49 total = sum(expense["amount"]for expense in expenses.values()) print (f"\nTotal Expenses : £{total:.2f}\n") 31 32 def generate_report(): 33 34 v 35 36 37 def main(): 38 v 39 40 41 42 43 44 45 46 v print("\nexpense Report:\n ") for timestamp, expense in expenses.items(): print(f"{timestamp} - {expense['item_name']} ({expense['category']}): £{expense['amount']:.2f}") while True: 50 ✓ 51 52 v 53 54 AI () Python print("Expense Tracker Menu: ") print("1: Add an Expense") print("2: Calculate Total ") print("3: Generate Report") print("4: Exit") choice = input ("Enter a choice (1-4): ") if choice == "1": add_expense() elif choice == "2": calculate_total() elif choice == "3": generate_report() elif choice == '4': print("leaving Expense tracker.") break
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

please create a test for this code 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education