Created
November 9, 2015 06:17
-
-
Save NotTheEconomist/77af58a43bdcaf9c57ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Dish(object): | |
def __init__(self, name, price, calories): | |
self.name = name | |
self.price = price | |
self.calories = calories | |
@classmethod | |
def _get_info(cls): | |
name = input("Please enter the dish's name: ") | |
price = float(input("Please enter the dish's price: ")) | |
calories = int("Please enter the dish's calories: ") | |
return cls(name, price, calories) | |
def __str__(self): | |
return "\n".join([ self.name, | |
"Price: ${:.2f}".format(self.price), | |
"Calories: {}".format(self.calories)]) | |
get_info = Dish._get_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dish | |
def menu_enter(): | |
menu = [] | |
while True: | |
n = input("Do you want to add a dish? ") | |
if n.lower() == 'yes': | |
d = dish.get_info() | |
menu.append(d) # or str(d) maybe? I'd want to keep the dish object! | |
else: | |
for dish in menu: | |
print(dish) | |
print() # empty line between dishes | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment