Oct-21-2022, 08:58 PM
(This post was last modified: Oct-21-2022, 08:58 PM by Yoriz.
Edit Reason: Added code tags
)
Hi. This is my first post ever in a Python forum, and I'm a beginner so please bear with me
I have two sets of codes called restaurant.py and test_restaurant.py
My purpose is to use test_restaurant.py to import a class from restaurant.py.
I have made an instance in test_restaurant.py and want to display only the values from this instance. But when I run the code it includes all the other outputs from the module (restaurant.py). Why am I seeing everything and not only what I have specified in my code (test_restaurant.py)?
restaurant.py:
Thanks!
I have two sets of codes called restaurant.py and test_restaurant.py
My purpose is to use test_restaurant.py to import a class from restaurant.py.
I have made an instance in test_restaurant.py and want to display only the values from this instance. But when I run the code it includes all the other outputs from the module (restaurant.py). Why am I seeing everything and not only what I have specified in my code (test_restaurant.py)?
restaurant.py:
# restaurant.py
class Resto():
"""Building a restaurant code"""
def __init__(self, restaurant_name, cuisine_type):
"""Initialize name and type attributes."""
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
"""prints these two pieces of information"""
print(self.restaurant_name.title() + " is a " + self.cuisine_type
+ " restaurant type.")
def open_restaurant(self):
"""Prints a message that indicates that the restaurant is open."""
print(self.restaurant_name.title() + " is now open.")
my_resto = Resto('dinner', 'fine dining')
your_resto = Resto('mc donalds', 'fastfood')
their_resto = Resto('alex sushi', 'sushi restau')
our_resto = Resto('big horn', 'steakhouse')
print("I always love to go to " + my_resto.restaurant_name.title() + ".")
print("This type of restaurant is: " + my_resto.cuisine_type + ".")
my_resto.describe_restaurant()
your_resto.describe_restaurant()
their_resto.describe_restaurant()
our_resto.describe_restaurant()
my_resto.open_restaurant()test_restaurant.py# Test to import restaurant.py, class Resto()
from restaurant import Resto
my_test = Resto('max burger', 'fastfood')
my_test.describe_restaurant()I'd be grateful if someone could help me with this beginner challenge
Thanks!
