由于繁忙的工作不得不把学习暂停一段落,还好,终于可以接着学习了。

def make_omelet(omelet_type):

"""This will make an omelet. You can either pass in a dictionary that

contains all of the ingredients for your omelet, or provide a string to select

a type of omelet this funcion already knows about"""

def get_omelet_ingredients(omelet_name):

"""This contains a dictionary of omelet names that can be produce and

their ingredients"""

ingredients={"eggs":2,"milk":1}

if omelet_name=="cheese":

ingredients["cheddar"]=2

elif omelet_name=="western":

ingredients["jack_cheese"]=2

ingredients["ham"]=1

ingredients["pepper"]=1

ingredients["onion"]=1

elif omelet_name=="greek":

ingredients["feta_cheese"]=2

else:

print("That's not on the menu, sorry!")

return None

return ingredients

if type(omelet_type)==type({}):

print("omelet_type is a dictionary with ingredients")

return make_food(omelet_type,"omelet")

elif type(omelet_type)==type(""):

omelet_ingredients=get_omelet_ingredients(omelet_type)

if omelet_ingredients==None:

return None

else:

return make_food(omelet_ingredients,omelet_type)

else:

# print("I don't think I can make this kind of omelet:%s" % omelet_type)

raise TypeError("No such omelet type: %s"% omelet_type)


def make_food(ingredients_needed,food_name):

"""make_food(ingredients_needed,food_name) takes the ingredients from

ingredients_needed and makes food_name"""

for ingredient in ingredients_needed.keys():

print("Adding %d of %s to make a %s"%

(ingredients_needed[ingredient],ingredient,food_name))

print("Made %s" % food_name)

return food_name

这是今天学习的函数,不错,调试出了预期结果。