返回值

# 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

你可能感兴趣的:(返回值)