Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

we are using python and please add discription 1) [25 marks] Write a function named add item that takes the inventory dictionary as its parameter.

we are using python and please add discription
image text in transcribed
image text in transcribed
1) [25 marks] Write a function named add item that takes the inventory dictionary as its parameter. This function will ask the user to enter the name of an item. If the item is in the inventory, the user will be asked to enter the number of this item to add to the inventory. If the item is not in the inventory, the user will be asked for a price for the item as well has the number of items to add to the inventory. NOTE: the price and count will be keys to a dictionary that comprise the value for the item, e.g. \{"Banana": f"price": 1.99, "count": 15\}\}. "price" is a float and "count" is an int. Error checking must be implemented to ensure that an empty string is not entered for the name of the item and that "price" and "count" are not empty strings but are float and int respectively. When an item is added to the inventory, the first letter will be capitalized and a success message will be displayed. This function will return None. For example: add_item(inventory) Enter the name of the item: Enter the name of the item: poncho Enter the price of this item (format: 21.67): Enter the price of this item (format: 21.67 ): red Enter the price of this item (format: 21.67): 5 Enter the price of this item (format: 21.67 ): 15.67 Enter the number of items: Enter the number of items (must be an integer): 5,4 Enter the number of items (must be an integer): red Enter the number of items (must be an integer): 20 20 oncho (s) have been added to inventory 2) [25 marks] Write a function called remove item that takes the inventory dictionary as its parameter. This function will ask the user to enter the name of the item. If the item is not in the inventory, a message will be displayed and the function will end returning None. If the item is in the inventory, the user will be asked how many of the item to remove and then remove this many of the item from the inventory. Error checking must be implemented to ensure that "count" is an int. For example: remove item(inventory) Enter the name of the item: duck There are no Duck (s) in inventory remove_item(inventory) Enter the name of the item: belt How many Belt (s) would you like to remove?: 2.5 Enter the number of items (must be an integer): red Enter the number of items (must be an integer): 5 5 Belt (s) have been removed from inventory 3) [30 marks] Write a function called calc worth that takes the inventory dictionary as its parameter. This function will calculate and display alphabetically the net worth of 2 each item in the inventory as well as the net worth of all items in the inventory. NOTE: " 1:,.2f}" ". format (float_num) will print a floating point number with 2 decimal places and a comma after every 3 digits. This function returns None. For example: calc_worth (inventory) There are 17 Belt (s) worth $594.15 There are 45 Shirt(s) worth $897.75 There are 85 Socks (s) worth $254.15 The total worth of the inventory is $1,746.05 4) [10 marks] Write a function called ma in that takes no parameters and returns None. This function initializes an empty dictionary for the inventory, displays a menu and waits for the user to make a selection, executes the selection, and displays the menu again until the exit selection is entered. Error checking must be implemented to ensure that only valid integers are entered as menu selections. This can be the same as in lab 1. Note: option 2 uses remove_item. For example: main() (1) Add an item to the inventory (2) Update an item in the inventory (3) Print the items in the inventory with there values (4) Quit Select option (1 to 4 ): a Invalid option. Please enter a number between 1 and 4:A Invalid option. Please enter a number between 1 and 4 : Invalid option. Please enter a number between 1 and 4:5 Invalid option. Please enter a number between 1 and 4:0 Invalid option. Please enter a number between 1 and 4:4 Goodbye

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

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

Discuss consumer-driven health plans.

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago