Question: Comma Code Say you have a list value like this: listToPrint = ['apples', 'bananas' Write a program that prints a list with all the

Comma Code Say you have a list value like this: listToPrint = ['apples', 'bananas' Write a program thatBackpack of stuff Complete the following code. Fill in the two sections of code identified in the comments.

Comma Code Say you have a list value like this: listToPrint = ['apples', 'bananas' Write a program that prints a list with all the items separated by a comma and a space, with and inserted before the last item. For example, the above list would print 'apples, bananas, tofu, and cats'. But your program should be able to work with any list not just the one shown above. Because of this, you will need to use a loop in case the list to print is shorter or longer than the above list. Make sure your program works for all user inputs. For instance, we wouldn't want to print "and" or commas if the list only contains one item. else: 'tofu', You can use the following code to start your program. It will let the user type a list listToPrint = [] while True: newWord = input("Enter a word to add to the list (press return to stop adding words) > ") if newWord == break listToPrint.append(newWord) 'cats'] Backpack of stuff Complete the following code. Fill in the two sections of code identified in the comments. import sys itemsInBackpack = ["book", "computer", "keys", "travel mug"] while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") Backpack of stuff Complete the following code. Fill in the two sections of code identified in the comments. import sys itemsInBackpack = ["book", "computer", "keys", "travel mug"] while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") userChoice = input() if(user Choice == "1"): print("What item do you want to add to the backpack?") itemToAdd = input() #######_YOUR CODE HERE ###### #add the item to the backpack #######_YOUR CODE HERE ###### if(userChoice == "2"): print("What item do you want to check to see if it is in the backpack?") itemToCheck = input() #######_YOUR CODE HERE ###### #Print out if the user's item is in the backpack #######_YOUR CODE HERE ###### if(userChoice == "3"): sys.exit()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1 create an empty list listToPrint loop that inputs words from user and adds it to list until user q... View full answer

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 Programming Questions!