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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 7PE
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage