American Young Coder (AYC)

Loading Events

« All Events

  • This event has passed.

1 PM – Indo – PythonOOP – Joel

October 14, 2023 @ 1:00 pm - 2:00 pm

Today we did:
  1. We went over some more examples of how OOP can be used in Python.
Homework:
  1. Create a new file called Oct14_RestaurantOOP.py. Inside the file, there will be a Restaurant class, and the attributes (in the constructor) are: name, cuisine, is_open, and rating. Name is the name of the restaurant, cuisine is the type of food (for example, Indonesian, Japanese, etc.) served at that restaurant, and rating (float is the data type, which is a decimal number) is the number of stars it has. For example, 4.5 stars is a pretty good restaurant, whereas 2 stars is not a good restaurant.
  2. There will be several methods:
  3. check_is_open(), which has no parameters (except for self, of course). If the is_open attribute is equal to false, then the method will print “{restaurant name} is not currently open”. If it is equal to true, print “{restaurant name is ready to serve you!”
  4. check_restaurant_rating(), which has no parameters. If the rating is below 3, then it prints “{restaurant name } only has {restaurant rating}. We are trying to improve our service. “. If not, then print “{restaurant name} has {restaurant rating}, it is a great restaurant.”
  5. check_cuisine(), which has one parameter: cuisine. When the user types in a cuisine, it checks whether what the user typed in is the same as the cuisine that the restaurant serves. If it is, print “We serve {restaurant cuisine}.” If not, “Sorry, we only serve {restaurant cuisine}”. It is up to you whether or not you want to make it case insensitive.
  6. getInfo(), which has no parameters. It will return a string that says this: {restaurant name} serves {restaurant cuisine} and has {restaurant rating} stars.
  7. Once you’re done with the class attributes and methods, feel free to create some restaurants outside the class and test out your code.

If you have any questions, feel free to email me at joel@ayclogic.com or Mr. Gamas at @gamas@ayclogic.com.

Details

Date:
October 14, 2023
Time:
1:00 pm - 2:00 pm
Verified by MonsterInsights