第四次作业
2018-04-01 16:24
253 查看
7-1汽车租赁:car = input("What kinds of car do you want to bent?")
print("Let me see if I can find you a "+ car)
7-2餐馆订位:peoples = input("How many people do you have?")
if int(peoples) > 8:
print("There is no more table!")
else:
print("There is a table!")
7-4披萨配料:promt = ("Add some toppings in your pizza!")
promt+=("\nThen input 'quit' to end the input!" )
while True:
topping = input(promt)
if topping == 'quit':
break;
else:
print("Ok,I will help you to add "+topping)
7-8熟食店:sandwich_orders = ['Apple_sandwiche','Cheese_sandwich','Pear_sandwich']
finished_sandwiches = []
while sandwich_orders:
current_sandwich = sandwich_orders.pop()
print("I made your "+ current_sandwich)
finished_sandwiches.append(current_sandwich)
print("The following sandwich have been finished!")
for finished_sandwich in finished_sandwiches:
print(finished_sandwich)
8-5城市:def city_country(city = 'Reykjavi',country = 'Iceland'):
print(city + ' is in '+ country)
city_country()
city_country('Blue River')
city_country('Paris','France')
for magican in magicans:
print(magican)
magicans = ['Alice','Jam','Benjuming']
show_magicans(magicans)
8-10了不起的魔术师:def show_magicans(magicans):
for magican in magicans:
print(magican)
def make_great(magicans,final_magicans):
while magicans:
current_magican = magicans.pop()
final_magicans.append(current_magican+' The Great')
magicans = ['Alice','Jam','Benjuming']
final_magicans=[]
show_magicans(magicans)
make_great(magicans,final_magicans)
print("After all the magicans adding the Great!")
show_magicans(final_magicans)
8-12三文治:def sandwiches_toppings(*toppings):
print("The sandwiches toppings listing as follows:")
for topping in toppings:
print(topping)
sandwiches_toppings('Chess')
sandwiches_toppings('Chess','Apple')
sandwiches_toppings('Chess','Apple','Rasabi')
8-13用户简介:def build_profile(first, last, **user_info):
"""创建一个字典,其中包含我们知道的有关用户的一切"""
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for key, value in user_info.items():
profile[key] = value
return profile
my_profile = build_profile('Stepthon', 'Curry',
location='GuangZhou',
field='Computer')
print(my_profile)
8-16导入函数:
text.py模板的 build_profile函数:def build_profile(first, last, **user_info):
"""创建一个字典,其中包含我们知道的有关用户的一切"""
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for key, value in user_info.items():
profile[key] = value
return profile1.利用import mudule_name:usage.py模板调用 text.py模板的build_profile函数:import text
my_profile = text.build_profile('Stepthen','Curry',location = 'Guangzhou',field = 'Computer')
print(my_profile)
2.利用from mudule_name import function_name:
my_profile = t.build_profile('Stepthen','Curry',location = 'Guangzhou',field = 'Computer')
print(my_profile)
5 from module_name import *
测试结果都为:
print("Let me see if I can find you a "+ car)
What kinds of car do you want to bent?Subaru Let me see if I can find you a Subaru
7-2餐馆订位:peoples = input("How many people do you have?")
if int(peoples) > 8:
print("There is no more table!")
else:
print("There is a table!")
How many people do you have?8 There is a table!
7-4披萨配料:promt = ("Add some toppings in your pizza!")
promt+=("\nThen input 'quit' to end the input!" )
while True:
topping = input(promt)
if topping == 'quit':
break;
else:
print("Ok,I will help you to add "+topping)
Add some toppings in your pizza! Then input 'quit' to end the input!Cheese Ok,I will help you to add Cheese Add some toppings in your pizza! Then input 'quit' to end the input!quit Process finished with exit code 0
7-8熟食店:sandwich_orders = ['Apple_sandwiche','Cheese_sandwich','Pear_sandwich']
finished_sandwiches = []
while sandwich_orders:
current_sandwich = sandwich_orders.pop()
print("I made your "+ current_sandwich)
finished_sandwiches.append(current_sandwich)
print("The following sandwich have been finished!")
for finished_sandwich in finished_sandwiches:
print(finished_sandwich)
I made your Pear_sandwich I made your Cheese_sandwich I made your Apple_sandwiche The following sandwich have been finished! Pear_sandwich Cheese_sandwich Apple_sandwiche
8-5城市:def city_country(city = 'Reykjavi',country = 'Iceland'):
print(city + ' is in '+ country)
city_country()
city_country('Blue River')
city_country('Paris','France')
Reykjavi is in Iceland Blue River is in Iceland Paris is in France8-9魔术师:def show_magicans(magicans):
for magican in magicans:
print(magican)
magicans = ['Alice','Jam','Benjuming']
show_magicans(magicans)
Alice Jam Benjuming
8-10了不起的魔术师:def show_magicans(magicans):
for magican in magicans:
print(magican)
def make_great(magicans,final_magicans):
while magicans:
current_magican = magicans.pop()
final_magicans.append(current_magican+' The Great')
magicans = ['Alice','Jam','Benjuming']
final_magicans=[]
show_magicans(magicans)
make_great(magicans,final_magicans)
print("After all the magicans adding the Great!")
show_magicans(final_magicans)
Alice Jam Benjuming
After all the magicans adding the Great!
Benjuming The Great
Jam The Great
Alice The Great
8-12三文治:def sandwiches_toppings(*toppings):
print("The sandwiches toppings listing as follows:")
for topping in toppings:
print(topping)
sandwiches_toppings('Chess')
sandwiches_toppings('Chess','Apple')
sandwiches_toppings('Chess','Apple','Rasabi')
The sandwiches toppings listing as follows: Chess The sandwiches toppings listing as follows: Chess Apple The sandwiches toppings listing as follows: Chess Apple Rasabi
8-13用户简介:def build_profile(first, last, **user_info):
"""创建一个字典,其中包含我们知道的有关用户的一切"""
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for key, value in user_info.items():
profile[key] = value
return profile
my_profile = build_profile('Stepthon', 'Curry',
location='GuangZhou',
field='Computer')
print(my_profile)
{'first_name': 'Stepthon', 'last_name': 'Curry', 'location': 'GuangZhou', 'field': 'Computer'}
8-16导入函数:
text.py模板的 build_profile函数:def build_profile(first, last, **user_info):
"""创建一个字典,其中包含我们知道的有关用户的一切"""
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for key, value in user_info.items():
profile[key] = value
return profile1.利用import mudule_name:usage.py模板调用 text.py模板的build_profile函数:import text
my_profile = text.build_profile('Stepthen','Curry',location = 'Guangzhou',field = 'Computer')
print(my_profile)
2.利用from mudule_name import function_name:
from text import build_profile my_profile = build_profile('Stepthen','Curry',location = 'Guangzhou',field = 'Computer') print(my_profile)3.利用from module_name import function_name as fn
from text import build_profile as b my_profile = b('Stepthen','Curry',location = 'Guangzhou',field = 'Computer') print(my_profile)4.利用import module_name as mnimport text as t
my_profile = t.build_profile('Stepthen','Curry',location = 'Guangzhou',field = 'Computer')
print(my_profile)
5 from module_name import *
from text import * my_profile = build_profile('Stepthen','Curry',location = 'Guangzhou',field = 'Computer') print(my_profile)
测试结果都为:
{'first_name': 'Stepthen', 'last_name': 'Curry', 'location': 'Guangzhou', 'field': 'Computer'}