Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm Stuck
#1
Hi, I was wondering if anyone could help me with this code. When I enter any word (Thing, in this example) it comes up with this error:


Output:
[['Starter', 'Main', 'Dessert', 'Drink']] Please enter your starter dish :  Thing
Error:
Traceback (most recent call last):  File "python", line 39, in <module>  File "python", line 34, in main  File "python", line 17, in add_data_rows  File "python", line 9, in get_string_inputs  File "<string>", line 1, in <module> NameError: name 'Thing' is not defined
This is my code, and I honestly have no idea why this is happening.

favMeal = []
header = ['Starter','Main','Dessert','Drink']
favMeal.append(header)

print(favMeal)

def get_string_inputs(p):
  
  strData = input("Please enter {0}: ".format(p))
  return strData
  
  
def add_data_rows():
  
  meal_details = [ ]
  
  starter_c = get_string_inputs("your starter dish ")
  meal_details.append(starter_c)
  main_c = get_string_inputs("your main course ")
  meal_details.append(main_c)
  dessert_c = get_string_inputs("your dessert course ")
  meal_details.append(dessert_c)
  drink = get_string_inputs("your drink ")
  meal_details.append(drink)
  return meal_details
  
def main():
  
  
  favMeal= [ ]
  header = ['Starter','Main', 'Dessert', 'Drink']
  favMeal.append(header)
  
  meal_details = add_data_rows()
  favMea.append(meal_details)
  for a,b,c,d in favMeal:
    print('{0:<16} {1:<16} {2:<16} {3:<16}'.format(a,b,c,d))
    
main()
Any help would be greatly appreciated.
Reply
#2
is this homework or an assignment?
Recommended Tutorials:
Reply
#3
It is a homework we were given to complete for Thursday, and add a new section to it. We had to follow the sheet we were given. Even though I have typed it out exactly as printed, it comes up with an error.
Reply
#4
Typo!

favMea.append(meal_details) # here <<<
  for a,b,c,d in favMeal:
    print('{0:<16} {1:<16} {2:<16} {3:<16}'.format(a,b,c,d))
Your code is a bit messy
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
I've corrected the spelling, but it still comes up with the same error.

I keep looking through it, I just can't see what'd be wrong with it.
Reply
#6
I get a completely different error (also a mispelling)
change:
  favMea.append(meal_details)
To:

  favMeal.append(meal_details)
Reply
#7
I've changed the error, twas pointed out previously, but it still comes up with the same error.
Reply
#8
How do you run the script?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
I use repl.it to write and execute my code, it's a free online Python platform.
Reply
#10
If you can, run it on Python 3
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

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