python课程作业——第8章 函数

第8章 函数

这里写图片描述

# 8-12
def printMaterial(name, *materials):
    print("costumer " + name + ":")
    for material in materials:
        print(material)
    print()


printMaterial("John", "beef", "tuna")
printMaterial("Alice", "peanut")
printMaterial("Tom", "tomato", "egg", "cheese")

# 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


user_profile = build_profile(
    'albert', 'ye', location='guangzhou', field='computer science')
print(user_profile)

# 8-14
def make_car(name, location, **car_info):
    profile = {}
    profile['name'] = name
    profile['location'] = location
    for key, value in car_info.items():
        profile[key] = value
    return profile


car = make_car('subaru', 'outback', color='blue', tow_package=True)
print(car)

猜你喜欢

转载自blog.csdn.net/yeziqing10/article/details/80628789