Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

what a proplem thats is code import sys # Function to display menu, accept user choice and returns it def menu(): # Displays menu print('

what a proplem

thats is code

import sys

# Function to display menu, accept user choice and returns it def menu(): # Displays menu print(' Supermarket Management System') print('=============================') print('1. Print items info') print('2. Search for an item') print('3. Add new item') print('4. Remove an item') print('5. Sell an item') print('6. Update an item') print('7. Exit') print('=============================') # Accepts user choice choice = int(input('Enter your choice: ')) # Returns user choice

# Defines function to read item information from file def readItems(): # List to store the items read from file items = [] # Opens the file for reading with open('superMarketItems.txt') as inFile: # Reads a record from file one at a time for record in inFile: # Removes the black space and split it with "," values = (record.strip()).split(",") # Appends the student data in studentScore list items.append(values) # Close the file inFile.close() # Returns the list return items

# Function to display item information def printItems(items): # Displays heading print("%-5s %-20s %-7s %-10s" % ("SN", "Item Name", "Price", "Total Items")) # Loops till end of the list for it in items: # Displays current item information print("%-5d %-20s %-7d %-10d" % (int(it[0]), it[1],float(it[2]), int(it[3])))

# Function to search an item information def searchItems(items, choice): # List to store the items found foundItems = []

# Checks if parameter choice value is 1 if choice == 1: # Accepts serial number serialNumber = int(input('Enter serial number of the item: '))

# Loops till end of the items list for c in range(len(items)): # Checks if c index position item 0th index position serial number # is equals to user entered seriel number if int(items[c][0]) == serialNumber: # Adds the c index position item to foundItems list foundItems.append(items[c])

# Otherwise checks if parameter choice value is 2 elif choice == 2: # Accepts the item name itemName = input('Enter item name or part of it: ')

# Loops till end of the items list for c in range(len(items)): # Checks if user entered item name first character is equals to # c index position item's 1st index position item name if itemName[0] in items[c][1]: # Adds the c index position item to foundItems list foundItems.append(items[c])

# Otherwise invalid parameter choice value else: print('Invalid Choice')

# Returns the foundItems list return foundItems

# Function to accept item number and returns it def getItemNumber(items): # Loops till valid or unique item number not entered by the user while True: # Accepts item number itemNo = int(input('Enter item SN: ')) # Initial found index is -1 for not found foundIndex = -1 # Loops till end of the items list for c in range(len(items)): # Checks if c index position item 0th index position serial number # is equals to user entered item number if int(items[c][0]) == itemNo: # Assigns loop variable value as found index foundIndex = c

# Checks if found index is -1 then unique serial number if foundIndex == -1: # Returns the user entered item number return itemNo

# Otherwise duplicate item number else: print('Already exists.')

# Function to accept item name and returns it def getItemName():

# Loops till valid item name not entered by the user while True: # Accepts item name name = input('Enter item name: ')

# Checks if item name is not empty if len(name) != 0: # Returns the item name entered by the user return name # Otherwise displays error message else: print('Empty.')

# Function to accept item price and returns it def getPrice(): # Loops till valid item name not entered by the user while True: # Accepts item price price = input('Enter item Price: ')

# Checks if item price is not empty and not negative if len(price) != 0 and float(price) > 0.0: # Returns the item price entered by the user return price # Otherwise invalid price else: print('Price must be a positive value and non-empty.')

# Function to accept item quantity and returns it def getQuantity(): # Loops till valid item quantity not entered by the user while True: # Accepts item quantity qty = input('Enter number of available items: ')

# Checks if item quantity is not empty and not negative if len(qty) != 0 and int(qty) > 0: # Returns the item quantity entered by the user return qty # Otherwise invalid quantity else: print('Must be positive value and non-empty.')

# Function to add an item to items list def addItem(items): # Calls the function to get item serial number itemNo = getItemNumber(items) # Calls the function to get item name name = getItemName() # Calls the function to get item price price = getPrice() # Calls the function to get item quantity qty = getQuantity()

# Adds the item to items list items.append([itemNo, name, price, qty]) print('Item has been added')

# Function to remove an item from items list def removeItem(items): # Accepts an item number itemNo = int(input('Enter serial number of the item: ')) # Initial found index is -1 then not found foundIndex = -1

# Loops till end of the items list for c in range(len(items)): # Checks if c index position item 0th index position serial number # is equals to user entered item number if int(items[c][0]) == itemNo: # Assigns loop variable value as found index foundIndex = c

# Checks if found index is -1 then unique serial number if foundIndex == -1: print('Not exist.')

# Otherwise found else: # Displays the heading print("%-5s %-20s %-7s %-10s" % ("SN", "Item Name", "Price", "Total Items"))

# Displays the found item print("%-5d %-20s %-7d %-10d" % (int(items[foundIndex][0]), items[foundIndex][1],float(items[foundIndex][2]), int(items[foundIndex][3])))

# Accepts user choice to delete choice = input('Are you sure you want to remove this item? [Y/N] ') # Converts the user choice to upper case choice = choice.upper()

# Checks if first character of user entered choice is 'Y' if choice[0] == 'Y': # Delete the found index item from items list del items[foundIndex] print('Removed successfully !!')

# Function to sell an item def sellItem(items): # Accepts an item number itemNo = int(input('Enter serial number of the item: '))

# Initial found index is -1 for not found foundIndex = -1

# Loops till end of the items list for c in range(len(items)): # Checks if c index position item 0th index position serial number # is equals to user entered item number if int(items[c][0]) == itemNo: foundIndex = c

# Checks if found index is -1 then not found if foundIndex == -1: print('Not exist.')

# Otherwise found else: # Accepts customer name name = input('Enter the name of the person who bought this item: ') print('Item has been sold to Ahmed!!!')

def updateItem(items): # Accepts an item number itemNo = int(input('Enter serial number of the item: '))

# Initial found index is -1 for not found foundIndex = -1

# Loops till end of the items list for c in range(len(items)): # Checks if c index position item 0th index position serial number # is equals to user entered item number if int(items[c][0]) == itemNo: foundIndex = c

# Checks if found index is -1 then not found if foundIndex == -1: print('Not exist.')

# Otherwise found else: # Calls the function to get item name name = getItemName() # Calls the function to get item price price = getPrice() # Calls the function to get item quantity qty = getQuantity()

# Assigns the accepted data at found index of items list items[foundIndex][1] = name items[foundIndex][2] = price items[foundIndex][3] = qty # Calls the function to read items from file and stores the return list items = readItems()

# Loops till user choice is not 7 while True: # Calls the function to accept user choice choice = menu()

# Checks if user choice is 1 if choice == 1: # Calls the function to display items printItems(items)

# Otherwise checks if user choice is 2 elif choice == 2: # Displays sub menu print('1. By Serial Number') print('2. By Item Name')

# Accepts user choice choice = int(input('Enter your choice: '))

# Calls the function to search item and stores the found list foundItems = searchItems(items, choice)

# Checks if foundItems list is not empty if len(foundItems ) != 0: # Calls the function to display items printItems(foundItems)

# Otherwise not found else: print('Not found.')

# Otherwise checks if user choice is 3 if choice == 3: # Calls the function to add an item to items list addItem(items) # Otherwise checks if user choice is 4 elif choice == 4: # Calls the function to remove an item from items list removeItem(items)

# Otherwise checks if user choice is 5 elif choice == 5: # Calls the function to sell an item sellItem(items)

# Otherwise checks if user choice is 6 elif choice == 6: # Calls the function to update an item updateItem(items)

# Otherwise checks if user choice is 7 elif choice == 7: sys.exit('')

#Otherwise invalid choice else: print ('Invalid Choice!')image text in transcribed

+ Facebook X EX My account X Leena Razsa-Cax A Course Project X course project X - * * F* Disposable Temp. x C The Problem in X + C O localhost:8888otebooks/Downloads/course%20project.ipynb Q N ES III Apps 4 9 MP as in YouTube a amazan. - To get... Country IP Ranges. ** O Reacting list Grammarly ....KI-alblle Instagram jupyter course project Last Checkpoint 21 hours ago (unsaved changes) Logout File Edit View Insert Cell Kernel Widgets Help Trusted Python 2 E + 2 e Run Ic updateItem(items) + Olherwise check user choice is 7 elif choice as 7: sys.exit() Otherwise invalid choice else: print (Invalid choice!") ----------------------------- 1. Print itens into 2. Search for an item 3. Add new item 4. Remove willen 5. Sell an item 6. Update an item 7. Exit ============================= Enter your choice: 4 ------------------- NancError Traceback (most recent call last) in 29 values (record strip().split(",) 30 # Appends the student data in studentScore list ---> 31 itoms.append(values) > 22 # Close the file 23 infile.close() NaneError: name 'items' is not defined Type here to search o 61F Rain A F E 7:05 PM 12/29/2021

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

What are the negative aspects of the performance appraisal?

Answered: 1 week ago

Question

1. Make sure praise is tied directly to appropriate behavior.

Answered: 1 week ago

Question

9.4 Explain the roles in career development.

Answered: 1 week ago

Question

8.6 Discusstwo techniques used for assessing training needs.

Answered: 1 week ago