© 2004-21

Using a 2D List (Array)

Using python to create a 2D list of data entered by the user
# monitor the cost of 5 items purchased over 4 weeks

# Create a list.
allCosts = []

# Append empty lists in first two indexes.

# Loop over rows.
for week in range(5):
	# Loop over columns.
	# now create a list for this week
	print("Week {}".format(week+1))
	costThisWeek = []
	for item in range(4):
		itemCost = float(input("Enter the cost of item  " + str(item+1)))
	# now append the cost of this weeks items to the whole list

# Display entire list.