Reference no: EM131878823
Comma Code -
Say you have a list value like this:
listToPrint = ['apples', 'bananas', 'tofu', 'cats']
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.
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
else:
listToPrint.append(newWord)
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(userChoice == "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()
Character Picture Grid -
Say you have a list of lists where each value in the inner lists is a one-character string, like this:
grid =
[['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['O', 'O', 'O', 'O', 'O', '.'],
['.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
You can think of grid[x][y] as being the character at the x- and y-coordinates of a "picture" drawn with text characters. The (0, 0) origin will be in the upper-left corner, the x-coordinates increase going right, and the y-coordinates increase going down.
Copy the previous grid value, and write code that uses it to print the image.
..OO.OO..
.OOOOOOO.
.OOOOOOO.
..OOOOO..
...OOO...
....O....
Attachment:- Assignment File.rar