返回值

作者: 庵下桃花仙 | 来源:发表于2018-11-07 21:59 被阅读2次
# 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

相关文章

  • Rust 入门 - 方法

    函数/方法 无返回值 有返回值 语句不会返回值,表达式会返回值

  • 19-函数的返回值和参数进阶

    函数 函数根据有无参数以及有无返回值,可分为 有返回值,有参数 有返回值,无参数 无返回值,有参数 无返回值,无参...

  • Swift-函数

    函数的定义与调用 无参数函数,有返回值(返回值类型String) 多参数函数,有返回值(返回值类型String) ...

  • Day7-函数

    1、函数的返回值 1.1 函数的返回值: python 中每个函数都是有返回值的,返回值就是return 后面的值...

  • shell编程之特殊流程控制语句

    exit [返回值] 如果 exit 命令之后定义了返回值,那么这个脚本执行之后的返回值就是我们自己定义的返回值。...

  • ES8-async函数

    async函数返回值 await返回值 案例

  • 03.JavaScript对象

    对象 运行图片 方法 未点击无参无返回值有参无返回值有返回值有返回值 对象的创建方式 结果

  • JS 章节②. 基础应用(中) : 深入JavaScript

    1.函数返回值 返回值1 返回值2 返回值3 一般求和 多个参数求和 (arguments 是一个可变数组 ) ...

  • ★22.函数的形参与返回值的类型确定法则

    返回值 禁止返回局部变量的引用。 类的get函数返回值:内置类型返回值应为值类型,类类型返回值通常为const &...

  • #关于函数

    一、无参数 无返回值 二、有参数 无返回值 三、无参数 有返回值 四、有参数 有返回值 五、递归函数 自己调用自...

网友评论

    本文标题:返回值

    本文链接:https://www.haomeiwen.com/subject/thvbxqtx.html