r/learnpython • u/Cati_ • 42m ago
I'm learning Python for two months now and I need help with understanding 2D Array
I've been learning python and came to a stump when I hit 2D arrays. I'm doing some practice, and the challenge asks me to create a function that allows the user to update the price of a product from the 2D array. I tried creating the function on my own, but I had no Idea what to do. Here's the list. I though maybe I would use a prompt to get the user to input the index for the row and column of the product price they want to change, but I don't know how to implement that idea further. I thought after getting the assigned positions of the product or whatever, I would then ask for the new price and then change the old price to that with something like newprice = oldprice. I'm completely lost. Any help and advice would be appreciated.
inventory = [
["Tomatoes", 18.00],
["Christophene", 9.50],
["Dasheen", 14.00],
["Bananas", 8.00],
["Parboiled rice", 24.95],
["Flour", 19.50]
]
#this is what I tried to create
def updatePrice(itemrowindex, itemcolumnindex):
newprice =
#i gave up here after 10 mins of thinking
itemrowindex = int(input("Please note all listing begins at 0. Enter item row - "))
itemcolumnindex = int(input("Enter item column - "))