create a python script using the requirements and explain how it functions, please. I have added my starter code to work from as well as my desired outcome in the examples below. I attached my stater code in a screenshot as it was too long to include in my question for this exercise.

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
Topic Video
Question

create a python script using the requirements and explain how it functions, please. I have added my starter code to work from as well as my desired outcome in the examples below. I attached my stater code in a screenshot as it was too long to include in my question for this exercise.

you will complete a program that keeps track of the inventory of items a wizard is carrying. Your program will allow the user to show/add/remove/modify the items the wizard is carrying.

You are given a partially written code for this program;
your job is to write 4 functions that implement response to user commands. Read and understand the existing code –it has implemented the functions that handle printing welcome messages and the rules, and also the main function that handles the command loop. You are supposed to implement four functions -show, grab_item, drop_item, edit_item-that accept two lists: a list containing the names of the items and the other containing the weights of the items. The main function initializes the names list with 3 items “wooden staff”, “wizard hat”, “cloth shoes” and the weights list with weights of those items as 30.0, 1.5, 5.3 lbs respectively.
Here's what each function that you are implementing is supposed to do:
1.show: Lists the items that the wizard is currently carrying along with the index for each item and the weight of that item. See sample runs below. As shown in the sample this function also prints the total weight of the items along with the max weight limit of 100 lbs.Hint: You can use the sum function in Python to calculate the sum of weights. E.g. sum(weights) will return the sum of all the items in the weights list.
2.grab_item: Add a new itemwhile enforcing the following policy: There is a limit of 4 on the number of items the wizard can carryand a limit of 100 lbs on the total weightthe wizard can carry. So specifically, if the wizard is already carrying 4 items, print message that “You can't carry anymore items. Drop something first.”And return out of the function. Otherwise prompt the user for the name and the weight of the new item. Next check whether with the addition of the new item,the total weight will exceed the limit of 100 lbs. If so, print a message saying the weight limit will be exceeded, so cannot add the new item and return it out of the function. Otherwise, add the new name and weight to the two lists. See Sample runs below. Hint: You can use the sum function in Python to calculate the sum of weights. E.g. sum(weights) will return the sum of all the items in the weights list.
3.edit_item: Allow the user to update (only) the name of one of the items. Prompt the user for the index of the item to be edited. Validate that the index is between 1 and the current count of items.If invalid, print a message to that effect and exit. Otherwise prompt the user for the new name and update the name of the item. Print that the item was updated successfully. See Sample runs below.
4.drop_item: Prompt the user for the index of the item to be dropped. Validate that the index is between 1 and the current count of items. Remove the item from both lists. Print that the item was removed successfully. See Sample runs below.Read the description above and the sample runs shown below closely to understand what each command does. Add useful comments throughout the code.
 
 
def drop item(names, weights):
## Program that keeps track of the inventory of items a wizard is
##*# carrying. The program allows the user to show/add/remove/
##** edit the items the wizard is carrying.
''' Function to drop an item from the two lists
the index of the item to be dropped.
between 1 and count of items.
from the list.
Prompt the user for
Validate that the index is
Remove the item at the given index
pass + To be implemented
def main () :
WEIGHT_LIMIT = 100
display title()
COUNT_LIMIT = 4def
display title () :
display menu ()
print ("The Wizard Inventory program")
* all players start with these 3 items
print ()
inventory names = ["wooden staff", "wizard hat", "cloth shoes"]
def display menu () :
inventory weights = [30.0, 1.5, 5.3]
while True:
print ("COMMAND MENU")
print ("show
w - Show all items")
command = input ("Command: ")
if command == "show":
print ("grab - Grab an item")
show (inventory nameg, inventory weightS)
wwm mp
print ("edit
print ("drop
- Edit an item")
- Drop an item")
elif command -- "grab":
print ("exit - Exit program")
grab item (inventory names, inventory weights)
print ()
elif command == "edit":
def show (names, weights) :
edit item(inventory names, inventory weights)
elif command == "drop":
Function to show the items listed in names and weights list in
index name (weight lbs) At the end print the current
of the items and the weight limit of 100 lbs.''
ww
the form:
drop item (inventory names, inventory weights)
total weight
pass To be implemented
elif command == "exit":
def grab item(names, weights):
break
''' Function to add an item to the items list. Check if the lists
already have 4 items, then print a message saying cannot add more and
exit.
new item
limit of 100 lbs will be exceeded. If so, print a message saying
weight limit will be exceeded, cannot add item and exit
name and weight to the two lists.
else:
print ("Not a valid command. Please try again.\n") _
otherwise prompt the user for the name and the weight of the
Check if with the addition of the new item the weight
print ("Bye!")if __name == " main ":
main()
Add the new
pass + To be implemented
def edit item(names, weights) :
''' Function to edit name of an item from the two lists
the user for the index of the item to be edited.
Prompt
Validate that the
If invalid index, print a
else prompt the user for the
pass #
index is between 1 and count of items.
message stating the index is invalid
new name and update the name of the correct
To be implemented
item.
Transcribed Image Text:def drop item(names, weights): ## Program that keeps track of the inventory of items a wizard is ##*# carrying. The program allows the user to show/add/remove/ ##** edit the items the wizard is carrying. ''' Function to drop an item from the two lists the index of the item to be dropped. between 1 and count of items. from the list. Prompt the user for Validate that the index is Remove the item at the given index pass + To be implemented def main () : WEIGHT_LIMIT = 100 display title() COUNT_LIMIT = 4def display title () : display menu () print ("The Wizard Inventory program") * all players start with these 3 items print () inventory names = ["wooden staff", "wizard hat", "cloth shoes"] def display menu () : inventory weights = [30.0, 1.5, 5.3] while True: print ("COMMAND MENU") print ("show w - Show all items") command = input ("Command: ") if command == "show": print ("grab - Grab an item") show (inventory nameg, inventory weightS) wwm mp print ("edit print ("drop - Edit an item") - Drop an item") elif command -- "grab": print ("exit - Exit program") grab item (inventory names, inventory weights) print () elif command == "edit": def show (names, weights) : edit item(inventory names, inventory weights) elif command == "drop": Function to show the items listed in names and weights list in index name (weight lbs) At the end print the current of the items and the weight limit of 100 lbs.'' ww the form: drop item (inventory names, inventory weights) total weight pass To be implemented elif command == "exit": def grab item(names, weights): break ''' Function to add an item to the items list. Check if the lists already have 4 items, then print a message saying cannot add more and exit. new item limit of 100 lbs will be exceeded. If so, print a message saying weight limit will be exceeded, cannot add item and exit name and weight to the two lists. else: print ("Not a valid command. Please try again.\n") _ otherwise prompt the user for the name and the weight of the Check if with the addition of the new item the weight print ("Bye!")if __name == " main ": main() Add the new pass + To be implemented def edit item(names, weights) : ''' Function to edit name of an item from the two lists the user for the index of the item to be edited. Prompt Validate that the If invalid index, print a else prompt the user for the pass # index is between 1 and count of items. message stating the index is invalid new name and update the name of the correct To be implemented item.
Sample Run 1: show/grab/edit/drop
2 "Python 3.8.1 Shell
Eile Edit Shell Debug Options Window Help
www.
The Wizard Inventory program
COMMAND MENU
show - Show all items
- Grab an item
grab
edit - Edit an item
drop - Drop an item
exit - Exit program
Command: show
1. wooden staff ( 30.0 lbs)
2. wizard hat ( 1.5 lbs)
3. cloth shoes ( 5.3 lbs)
Total Weight: 36.8 Weight Limit: 100 lbs
Command: grab
Name: Wand
Weight in lbs: 3
Wand ( 3.0 lbs ) was added.
Command: show
1. wooden staff ( 30.0 lbs)
2. wizard hat ( 1.5 lbs)
3. cloth shoes ( 5.3 lbs)
4. Wand ( 3.0 lbs)
|Total Weight: 39.8 Weight Limit: 100 lbs
Command: grab
You can't carry any more items. Drop something first.
Command: drop
Number: 2
wizard hat ( 1.5 lbs ) was dropped.
Command: edit
Number: 3
Enter updated name: Most Powerful Wand
Item number 3 was updated.
Command: show
|1. wooden staff ( 30.0 lbs)
2. cloth shoes ( 5.3 lbs)
3. Most Powerful Wand ( 3.0 lbs)
Total Weight: 38.3 Weight Limit: 100 lbs
Command:
Transcribed Image Text:Sample Run 1: show/grab/edit/drop 2 "Python 3.8.1 Shell Eile Edit Shell Debug Options Window Help www. The Wizard Inventory program COMMAND MENU show - Show all items - Grab an item grab edit - Edit an item drop - Drop an item exit - Exit program Command: show 1. wooden staff ( 30.0 lbs) 2. wizard hat ( 1.5 lbs) 3. cloth shoes ( 5.3 lbs) Total Weight: 36.8 Weight Limit: 100 lbs Command: grab Name: Wand Weight in lbs: 3 Wand ( 3.0 lbs ) was added. Command: show 1. wooden staff ( 30.0 lbs) 2. wizard hat ( 1.5 lbs) 3. cloth shoes ( 5.3 lbs) 4. Wand ( 3.0 lbs) |Total Weight: 39.8 Weight Limit: 100 lbs Command: grab You can't carry any more items. Drop something first. Command: drop Number: 2 wizard hat ( 1.5 lbs ) was dropped. Command: edit Number: 3 Enter updated name: Most Powerful Wand Item number 3 was updated. Command: show |1. wooden staff ( 30.0 lbs) 2. cloth shoes ( 5.3 lbs) 3. Most Powerful Wand ( 3.0 lbs) Total Weight: 38.3 Weight Limit: 100 lbs Command:
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Instruction Format
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