Kingsley Bawuah Kingsley Bawuah - 3 months ago 10
Python Question

NameError: name 'name' is not defined

Currently working through Python Crash course and this example is giving me trouble

class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
""" initializing name and cuisine attributes"""
self.restaurant_name = name
self.cuisine_type = c_type

def greeting(self):
"""simulate greetting with restaurant info..."""
print(self.name.title() + " is a " + self.c_type.title()
+ " type of restaurant.")

def open_or_nah(self):
""" wheteher or not the restaurant is open in this case they will be always"""
print(self.name.title() + " is open af")


china_king = Restaurant('china king', 'chinese')
china_king.greeting
china_king.open_or_nah


the console keeps giving me the error

Traceback (most recent call last):
File "python", line 16, in <module>
File "python", line 4, in __init__
NameError: name 'name' is not defined


I've searched around for the reason as to what is causing this but i can't figure it out. What's wrong?

Answer

Looks like a small mistake, just modify it in your __init__

self.name = restaurant_name