Hi, i came across a python tutorial and executed it. however i am not very sure i did it all the way. so i am posting it here for assistance if there any issues the experts can see and help explain them to me.
“”"
Try IT yourself
9-1. Restaurant: Make a class called Restaurant. The init() method for
Restaurant should store two attributes: a restaurant_name and a cuisine_type.
Make a method called describe_restaurant() that prints these two pieces of
information, and a method called open_restaurant() that prints a message indi-
cating that the restaurant is open.
Make an instance called restaurant from your class. Print the two attri-
butes individually, and then call both methods.
9-2. Three Restaurants: Start with your class from Exercise 9-1. Create three
different instances from the class, and call describe_restaurant() for each
instance.
“”"
class Restaurant:
"""A simple attempt tp model a restaurant"""
def __init__(self, name, cousine): # My __init___ Method:
# Attributes
self.name = name
self.cousine = cousine
# make a method called describe restaurant
def describe_restaurant(self):
# print these two pieces of information.
print(f"{self.name}")
print(f"{self.cousine}")
# Make a method indicating the restaurant is open
def open_restaurant(self):
print(f"{self.name} is open")
# Instance for the class
restaurant = Restaurant('Global Kitchen', 'Tokira')
# create three other instances and describe_restaurant()
amba = Restaurant('Spicy-Kitchen', 'Kontommre')
ramzy = Restaurant('lapei-kicthen', 'Banku')
bl = Restaurant('Blue-Hills Hotel', 'Tumpaani')
# print the two attributes:
print(f"{restaurant.name}")
print(f"{restaurant.cousine}")
# call the methods
restaurant.describe_restaurant()
restaurant.open_restaurant()
# call describe_restaurant with the three new instances
amba.describe_restaurant()
ramzy.describe_restaurant()
bl.describe_restaurant()
“”"
Users: Make a class called User. Create two attributes called first_name
and last_name, and then create several other attributes that are typically stored
in a user profile. Make a method called describe_user() that prints a summary
of the user’s information. Make another method called greet_user() that prints
a personalized greeting to the user.
Create several instances representing different users, and call both methods
for each user
“”"
Please note i have seen None twice in the results of this code, i just don’t understand how that is come about.
class User:
def __init__(self, firstname, lastname, age, education, married, employed):
self.firstname = firstname
self.lastname = lastname
self.age = age
self.education = education
self.married = married
self.employed = employed
def describe_user(self):
print(f'Profile: {self.firstname} {self.lastname}, {self.age} years old, a {self.education}, fully {self.married}, and {self.employed}')
def greet_user(self):
# Print a personalized message for your user
print(f"Hi {self.firstname} you are welcome:")
profile = User('Amin', 'Umar', 47, 'Developer', 'Married', 'Employed')
print(f"{profile.describe_user()}")
print(f"{profile.greet_user()}")