Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,853 members, 7,810,284 topics. Date: Saturday, 27 April 2024 at 05:24 AM

Python Programmers, Pls Help Me Out? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python Programmers, Pls Help Me Out? (1431 Views)

Python Programmers Hang-out / Python Programmers Lets Meet Here!!! / Hello Programmers.. Pls I Need HELP Here Urgently!!! (2) (3) (4)

(1) (Reply) (Go Down)

Python Programmers, Pls Help Me Out? by somto10: 5:11am On Aug 16, 2019
I started learning python about two weeks ago.
Am now at OOP and this is my first code,
what could be the error here?
have tried my best but......


class Restaurant():
def __init__ (self,restaurant_name,cuisine_type):
self.name = restaurant_name
self.type = cuisine_type

def describe_restaurant(self):
#attempt to describe a restaurant
print(self.name.title() + "serves" + cuisine.type + "food." )

def open_restaurant(self):
#open and welcome customers
print(self.name.title() + "is now open" "\nCome." "\nHave your favorite" + self.cuisine + "food." )

restaurant1 = Restaurant("big chill" , "italian" )

print(restaurant1.name)
print(restaurant1.cuisine)
restaurant1.describe_restaurant()


See the error i keep getting.

Traceback (most recent call last):
File "C:/Users/Ocep/.PyCharmCE2019.1/config/scratches/scratch_6.py", line 1, in <module>
class Restaurant():
File "C:/Users/Ocep/.PyCharmCE2019.1/config/scratches/scratch_6.py", line 18, in Restaurant
restaurant1.describe_restaurant()
NameError: name 'restaurant1' is not defined
Re: Python Programmers, Pls Help Me Out? by okosodo: 6:24am On Aug 16, 2019
You cannot put two "" inside a backslash. I hope it solves it but channel your questions to stack overflow.com for quick and easy response
Re: Python Programmers, Pls Help Me Out? by segbolon: 7:05am On Aug 16, 2019
change class Restaurant(): to class Restaurant:
Re: Python Programmers, Pls Help Me Out? by bizza45: 8:42am On Aug 16, 2019
Bro are u doing self tutorial or are u attending classes for it
Re: Python Programmers, Pls Help Me Out? by Venzee(m): 12:43pm On Aug 16, 2019
Try to to use the if Statement and the return function to specify what yo you want the class object to do.
And don't use a boolen condition.
If it trowback an error, that means you are using python2 and you need to install python3 inside you python lib by using pip installer.

Learn more about python Tutorial full course in our website. Just hit the link below.
https://idreamng.com/category/software-programming/
Re: Python Programmers, Pls Help Me Out? by Heathen(m): 4:31pm On Aug 16, 2019
class Restaurant():

def __init__(self, restaurant_name, cuisine_type):
self.name = restaurant_name
self.type = cuisine_type

def describe_restaurant(self):
# attempt to describe a restaurant
print(self.name.title() + ' serves ' + self.type + ' food.')

def open_restaurant(self):
# open and welcome customers
print(self.name.title() + 'is now open' + '\ncome' + '\nHave your favorite ' + self.type + ' food.')


restaurant1 = Restaurant('big Chill', 'italian')

print(restaurant1.name)
print(restaurant1.type)
restaurant1.describe_restaurant()


Just like you started pyhton 2 weeks ago.

I think the reason for the error is because you used the incorrect syntax in print funtion and also in restaurant1.cuisine should have been restaurant1.type because you're calling a variable

2 Likes

Re: Python Programmers, Pls Help Me Out? by Heathen(m): 4:31pm On Aug 16, 2019
Re: Python Programmers, Pls Help Me Out? by somto10: 6:39pm On Aug 16, 2019
lipsrsealed
bizza45:
Bro are u doing self tutorial or are u attending classes for it
Yea i do attend class online but i work my ass out on my leisure....
Re: Python Programmers, Pls Help Me Out? by bizza45: 12:33pm On Aug 17, 2019
somto10:
lipsrsealed Yea i do attend class online but i work my ass out on my leisure....

how much did u pay for it
Re: Python Programmers, Pls Help Me Out? by Powersurge: 4:29am On Aug 30, 2019
why are you using object (NAME) that is not among your def__init__ function? it ought to be self.restaurant_name= restaurant_name. The same is applicable to type. name and type never existed in your def function and here you are binding them with self. self.cuisine_type= cuisine_type.



remove name and type from your code and replace them with the appropriate variables you defined.
Re: Python Programmers, Pls Help Me Out? by CenturyCoder: 3:41pm On Sep 27, 2020
I think this code is much more better

class Restaurant:
def __init__(self, restaurant_name, cuisine_name):
self.restaurant_name = restaurant_name
self.cuisine_name = cuisine_name

def get_restaurant_name(self):
return self.restaurant_name

def get_cuisine_name(self):
return self.cuisine_name

def describe_restaurant(self):
restaurant_description = f"{self.restaurant_name} serves {self.cuisine_name}"

print(restaurant_description)

def open_restaurant(self):
restaurant_welcome_message = f"{self.restaurant_name} is now open \n Come \n Have your favourite {self.cuisine_name} food"

restaurant_name = "Mr Biggs"
cuisine = "Eba"

firstRestaurant = Restaurant(restaurant_name, cuisine)
print(firstRestaurant.get_restaurant_name())
print(firstRestaurant.get_cuisine_name())
firstRestaurant.describe_restaurant()
firstRestaurant.open_restaurant()

2 Likes

Re: Python Programmers, Pls Help Me Out? by commarrkss: 12:30am On Sep 19, 2022
HOW TO START RECHARGE CARD PRINTING BUSINESS WITH OUR MACHINE AND FREE SOFTWARE

Recharge card printing business is a lucrative one you can start with a minimum of N54,000 only. You can also make above N450,000 monthly printing recharges and vouchers with the right information and guides from Confidence Communications Limited
For more information on how you can successfully start your recharge business and make profits from it with our free software and userguide, Call Mr.David Azin on 09161908779,
Email: confidencecommes@gmail.com
www.confidencecomess..com
Buy Recharge Cards And Voucher Pins From Confidence Communications Limited Today and be on the part way to success

(1) (Reply)

How To Create Forum Website Like Nairaland / Download AOL Desktop Gold For Windows 10 (april 2020) / Smpp Professional With Good Knowledge Of The Nigerian Market.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.