Question: Creating a shopping list in Python. In the code, I append the shopping list with user input but can't relay the information back correctly. My

Creating a shopping list in Python. In the code, I append the shopping list with user input but can't relay the information back correctly. My instructions for the printList function are down below.

Complete the printList function so that it will display the items in the list. Print out the items as a simple bulleted list. For example:

Your shopping list: * pizza * milk * bread

Use a loop to process through the contents of the shared list. Print out each value in the list, prefixing the value with space, space, star, space.

this is an example of my current code:

# create a shared list

theList = []

def printMenu():

print('Here are the list of commands:')

print( '-p : Print the List')

print( '-e : Empty the List')

print( '-x : Exit')

print( '-h : Print this command list')

def addToList(item):

theList.append(item)

def getInput():

if len(theList) > 0:

print ('You have', len(theList),'in your list')

else:

print('You have your 0 items in your list.')

return input('Enter an item or command: ')

def printList():

pass

def emptyList():

while item == theList:

print('The list is empty')

def startProgram():

print('Welcome to the XYZ Shopping List Program')

def endProgram():

print('Thank you for using the XYZ Shoppling List Program.')

def main():

startProgram()

printMenu()

item = getInput()

while item != '-x':

if item == '-p':

printList()

elif item == '-h':

printMenu()

elif item == '-e':

emptyList()

else:

addToList(item)

item = getInput()

endProgram()

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!