Skip to content

Instantly share code, notes, and snippets.

@NotTheEconomist
Created November 9, 2015 06:17
Show Gist options
  • Save NotTheEconomist/77af58a43bdcaf9c57ac to your computer and use it in GitHub Desktop.
Save NotTheEconomist/77af58a43bdcaf9c57ac to your computer and use it in GitHub Desktop.
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
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