Python编程从入门到实践(第二版)课后习题自写代码
最近自学的python,动手做了一下课后习题,错误也许会有,和大家一起探讨。多多指教!
动手试一试代码片
"""8-6 城市名"""
def city_country(city,country):
full_name = f"{
city},{
country}"
return full_name.title()
a = city_country('chengdu','china')
b = city_country('hangzhou','china')
c = city_country('guangzhou','china')
print(a)
print(b)
print(c)
"""8-7 专辑"""
def make_album(singer_name,album_name,sing_number=None):
album_info = {
's_name':singer_name,'a_name':album_name}
if sing_number:
album_info['sing_number'] = sing_number
return album_info
one = make_album('yiko','anti yiko',sing_number=7)
print(one)
two = make_album('eric','你好不好')
print(two)
three = make_album('taylor swift','love story')
print(three)
"""8-8 用户的专辑"""
def make_album(singer_name,album_name,sing_number=None):
album_info = {
's_name':singer_name,'a_name':album_name}
album_info['sing_number'