Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I need some help w/ dictionaries (Python 3)

+1 vote
asked Mar 11 by Colin Broyles (440 points)
Code:

ProductID = {}
ProductID[6969] = "Meme"
print(ProductID)
print(ProductID[input("What would you like to buy? (Imput product key)")])

How do I fix this?

1 Answer

0 votes
answered Mar 11 by KKN (1,090 points)
edited Mar 11 by KKN
ProductID = {}
#Would recommend just "69" not "6969" but you do you man.
ProductID[6969] = "Meme"
print(ProductID)

#Error Handling in case somebody does a funny >:P
try:
    #Making the input an integer
    buy = int(input("What would you like to buy? "))
    print("Bought:", "\"" + ProductID[buy] + "\"", "ID:", buy)
except ValueError:
    print("The ProductID should be int(1234) not string(\"Hello World\")")
except KeyError:
    print("The", buy, "ProductID doesn't exist u dumb. I mean I literally printed it for u >:(")



I added some mean stuff, you can remove it if you want 8)

I know this won't really answer your question, but hopefully someone can elaborate.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...