Jan-15-2020, 12:41 PM
I am trying to follow a python youtube channel by Mosh Hamedani and I tried to write a simple piece of code after seeing his program. My basics are not that good. My program did not work. I was trying to write a program in which if the user enters the name of a vegetable the program gives the price of the vegetable. The program did not work. Please help me.
vegetable = input("Enter the names of vegetables: ")
price_mapping = {
"onion": "50",
"carrot": "20",
"tomato": "10"
}
output = ""
print("These are the prices of vegetables")
for ch in vegetable:
output += price_mapping.get(ch) + " "
print(output)This was the outputOutput:Enter the names of vegetables: onion carrot tomato
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/untitled/Test.py", line 12, in <module>
output += price_mapping.get(ch) + " "
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
These are the prices of vegetables
Process finished with exit code 1
