Created
November 23, 2015 09:45
-
-
Save liuderchi/a2b2b3054bdb2af67308 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
'''restaurant.py | |
Designing some problems for | |
Intro to Computer Science Lesson 1 ~ Lesson 3 Review Question Code | |
Course Source: https://www.udacity.com/course/viewer#!/c-cs101 | |
''' | |
menu = [ [ "大麥克" , "牛肉, 酸黃瓜, 起士" , 109 ], | |
[ "麥香魚" , "鱈魚, 起士, 美乃滋" , 99 ], | |
[ "麥香雞" , "雞肉, 生菜, 美乃滋" , 89 ] ] | |
sales = ["麥香魚", "大麥克", "大麥克", "麥香魚", "麥香魚", | |
"大麥克", "大麥克", "麥香魚", "麥香雞", "大麥克", | |
"麥香雞", "麥香雞", "大麥克" ] | |
def print_burger( menu ): | |
i = 0 | |
while i < 3 : | |
print ( menu[i][ 0 ] ) | |
i = i + 1 | |
def find_cheese_burger( menu ): | |
for meal in menu : | |
if meal[1].find( "起士" ) is not -1: | |
print ( meal[0] ) | |
def today_income( sales ): | |
income = 0 | |
while ( len(sales) > 0 ): | |
burger = sales.pop() | |
if burger == "大麥克": | |
income = income + 109 | |
if burger == "麥香魚": | |
income = income + 99 | |
if burger == "麥香雞": | |
income = income + 89 | |
print( income ) | |
print('list all burgers') | |
print_burger( menu ) | |
print('\n find cheese burger:') | |
find_cheese_burger( menu ) | |
print("\n sum of today's income") | |
today_income( sales ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment