返回值

# 8-6
def city_country(city, country):
    str = city.title() +", " + country.title()
    print(str)

city_country('tai wan', 'china')
city_country('diaoyu island', 'china')
city_country('washington', 'USA')

# 8-7
def make_album(people, song, num=''):
    if num:
        dic = {'singer': people.title(), 'album': song.title(), 'number': num}
    else:
        dic = {'singer': people.title(), 'album': song.title()}
    return dic

musician = make_album('zhou jielun', 'fan te xi')
print(musician)
musician = make_album('li jian', 'si shui liu nian')
print(musician)
musician = make_album('zhou huajian', 'jiang hu', 14)
print(musician)

# 8-8
def make_album(people, song, num=''):
    if num:
        dic = {'singer': people.title(), 'album': song.title(), 'number': num}
    else:
        dic = {'singer': people.title(), 'album': song.title()}
    return dic

while True:
    print("(enter 'q' at any time to quit)")
    name = input("Please enter the name of the singer: ")
    if name == 'q':
        break
    production = input("Please enter album name: ")
    if production == 'q':
        break
    num = input("Please enter the number of songs on the album: ")
    if num == 'q':
        break

    flag = make_album(name, production, num)
    print(flag)

Tai Wan, China
Diaoyu Island, China
Washington, Usa
{'singer': 'Zhou Jielun', 'album': 'Fan Te Xi'}
{'singer': 'Li Jian', 'album': 'Si Shui Liu Nian'}
{'singer': 'Zhou Huajian', 'album': 'Jiang Hu', 'number': 14}
(enter 'q' at any time to quit)
Please enter the name of the singer: zhou huajian
Please enter album name: jiang hu
Please enter the number of songs on the album: 14
{'singer': 'Zhou Huajian', 'album': 'Jiang Hu', 'number': '14'}
(enter 'q' at any time to quit)
Please enter the name of the singer: zhou jielun
Please enter album name: fan te xi
Please enter the number of songs on the album: 
{'singer': 'Zhou Jielun', 'album': 'Fan Te Xi'}
(enter 'q' at any time to quit)
Please enter the name of the singer: 
Please enter album name: 
Please enter the number of songs on the album: 
{'singer': '', 'album': ''}
(enter 'q' at any time to quit)
Please enter the name of the singer: li jian
Please enter album name: q
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容