Python Forum
Newbie needs help with a simple program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie needs help with a simple program
#1
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 output

Output:
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
Reply


Messages In This Thread
Newbie needs help with a simple program - by feynarun - Jan-15-2020, 12:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Suggestions for a simple data analysis program t4keheart 0 1,761 Mar-08-2021, 03:45 PM
Last Post: t4keheart
  logging in simple program Inkanus 1 1,682 Dec-18-2020, 02:36 PM
Last Post: snippsat
  I am a newbie.Help me with this simple piece of code feynarun 3 2,752 Jan-08-2020, 12:40 PM
Last Post: perfringo
  Python Program to Make a Simple Calculator jack_sparrow007 2 10,104 Oct-19-2018, 08:32 AM
Last Post: volcano63
  help with simple program juanb007 2 2,705 Dec-07-2017, 02:15 PM
Last Post: j.crater
  Some Confusing Program Errors (Newbie stuff) WildPictus 1 2,746 Sep-03-2017, 05:00 PM
Last Post: hbknjr
  Newbie help with simple script written for v3.3 and used on vs2.7, please? PaulMorrey 4 5,166 Dec-09-2016, 11:06 AM
Last Post: Kebap
  a 'simple' program, hard as .... to understand meems 3 5,100 Dec-04-2016, 10:59 PM
Last Post: meems
  Cant Get Powershell to run a python program from notepad++. Newbie help! Pythonerous 4 8,812 Oct-10-2016, 07:16 PM
Last Post: Pythonerous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020