Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this workout assignment, you are going to write The Grocery Shopping Budget Calculator to help you keep track of your expenses as you shop.

In this workout assignment, you are going to write The Grocery Shopping Budget Calculator to help you keep track of your expenses as you shop.
You've just received your monthly salary and decided to allocate a portion of it to restocking your kitchen with groceries. However, you want to ensure you stay within your budget. Write a Python program that prompts the user to input their grocery items along with their respective prices. The program should then calculate the total cost of the items and compare it to the user's budget. If the total cost exceeds the budget, the program should display a message indicating the overage. Otherwise, it should display a message indicating the remaining budget after the purchase.
The core functionality of the Grocery Shopping Budget Calculator revolves around iteratively gathering information from the user regarding their budget and the items they intend to purchase. Upon execution, the program prompts users to input their budget, ensuring that the entered value is a valid numerical representation. It then guides users through the process of inputting individual grocery items and their corresponding prices, enforcing validation rules to maintain data integrity. Once all necessary information is collected, the program performs calculations to determine the total cost of the groceries and assesses whether it aligns with the user's budget. Finally, it provides informative output messages based on the outcome of these calculations.
Inputs
The inputs of the program and their order are explained below. It is extremely important to follow this order with the same characters since we automatically process your programs. Thus, your work will be graded as 0 unless the order is entirely correct. Please see the "Sample Runs" section for some examples.
The prompts of the input statements to be used have to be exactly the same as the prompts of the "Sample Runs".
Here is the detailed information on the inputs and the input checks:
Budget Input: Upon execution, the program prompts users to input their budget by using the following prompt:
Enter your budget: .
Users are expected to enter a numerical value representing their budgetary limit. The program performs validation checks to ensure that the entered value is a valid numerical representation:
The format of the input budget must contain an integer number with one letter currency unit. For example, the user would input "4$" or "5"but cannot input "4.3$" or "four$". You may assume that the user always enters one letter currency. If the input budget is not a valid number, the program displays an error message prompting and will terminate immediately:
Budget must be an integer number
Grocery Item and Price Input: After entering the budget, users are guided through the process of inputting individual grocery items and their corresponding prices until the user prompts done by using the following prompt:
Enter the name of the item (or type 'done' to finish):
. The user is prompted to enter the name of each grocery item followed by its price in the specified format:
:
Where, is the name of the item, is the price of the item, and is the currency of the item. For example, the user would input "Apples: 2.50$" to indicate that they are purchasing apples for $2.50. You may assume that the input structure format is fixed (the name of the grocery item, followed by a colon (:) and a space, then the price of the item, and finally, the currency symbol.) and you dont have to make a validation. The format ensures consistency and ease of parsing for the program.
If the item is found to be a duplicate, the program notifies the user about the mistake by prompting:
Item already exists!
The program does not include the duplicate item and its associated price in the calculation of the total cost of groceries. Instead, it disregards the last entered price of the duplicate item when calculating the total cost.
Output
The Grocery Shopping Budget Calculator generates informative messages based on the outcome of the budget assessment process.
Total Cost Exceeds: If the calculation of the total cost exceeds the user's specified budget, it indicates that the user has overspent. The program informs the user about this situation by displaying a message that clearly states the overage amount:
Total cost exceeds your budget by .
Where represents the amount by which the total cost exceeds the budget, rounded to two decimal places and is the currency defined by the budget input..
Total Cost Within Budget: If the total cost of the groceries does not exceed the user's specified budget, it indicates that the user has not overspent. In this case, the program informs the user about the remaining budget after deducting the total cost of groceries:
You have

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions