第一周作业_Chapter 2 课后练习
2018-03-11 11:09
489 查看
2-1 简单消息
代码:
favorite_fruit = "apples"
print(favorite_fruit)
运行结果:
2-2 多条简单消息
代码:
favorite_fruit = "apples"
print(favorite_fruit)
favorite_fruit = "pears"
print(favorite_fruit)
运行结果:
2-3 个性化信息
代码:
usename = "Adam"
str = "Hey " + usename + ", would you like to watch movies with me?"
print(str)
运行结果:
2-4 调整名字的大小写
代码:
name = "Adam"
print(name.lower())
print(name.upper())
print(name.title())
运行结果:
2-5 名言
代码:
str = 'Fuller once said, "The darkest hour is that before the dawn."'
print(str)
运行结果:
2-6 名言2
代码:
famous_person = "Fuller"
message = famous_person + ' once said, "The darkest hour is that before the dawn."'
print(message)
运行结果:
2-7 剔除人名中的空白
代码:
name = "\tAdam\t"
print(name + ".\n---------------------\n")
print(name.lstrip() + ".")
print(name.rstrip() + ".")
print(name.strip() + ".")
运行结果:
2-8 数字8
代码:
print(2+6)
print(10-2)
print(2*4)
print(16/2)
运行结果:
2-9 最喜欢的数字
代码:
num = 6
message = "My favorite number is " + str(num) + "."
print(message)
运行结果:
2-10 添加注释
代码:
# coding=utf-8
num = 6
#str()将数字转化成字符串
message = "My favorite number is " + str(num) + "."
print(message)
运行结果:
2-11 python之禅
输入import this,显示:
代码:
favorite_fruit = "apples"
print(favorite_fruit)
运行结果:
2-2 多条简单消息
代码:
favorite_fruit = "apples"
print(favorite_fruit)
favorite_fruit = "pears"
print(favorite_fruit)
运行结果:
2-3 个性化信息
代码:
usename = "Adam"
str = "Hey " + usename + ", would you like to watch movies with me?"
print(str)
运行结果:
2-4 调整名字的大小写
代码:
name = "Adam"
print(name.lower())
print(name.upper())
print(name.title())
运行结果:
2-5 名言
代码:
str = 'Fuller once said, "The darkest hour is that before the dawn."'
print(str)
运行结果:
2-6 名言2
代码:
famous_person = "Fuller"
message = famous_person + ' once said, "The darkest hour is that before the dawn."'
print(message)
运行结果:
2-7 剔除人名中的空白
代码:
name = "\tAdam\t"
print(name + ".\n---------------------\n")
print(name.lstrip() + ".")
print(name.rstrip() + ".")
print(name.strip() + ".")
运行结果:
2-8 数字8
代码:
print(2+6)
print(10-2)
print(2*4)
print(16/2)
运行结果:
2-9 最喜欢的数字
代码:
num = 6
message = "My favorite number is " + str(num) + "."
print(message)
运行结果:
2-10 添加注释
代码:
# coding=utf-8
num = 6
#str()将数字转化成字符串
message = "My favorite number is " + str(num) + "."
print(message)
运行结果:
2-11 python之禅
输入import this,显示:
相关文章推荐
- 第五周作业_Chapter 9课后练习
- 第三周作业_Chapter 5课后练习
- 第四周作业_Chapter 7课后练习
- 第四周作业_Chapter 8课后练习
- 第六周作业_Chapter 11课后练习
- 第五周作业_Chapter 10课后练习
- python 核心编程课后练习(chapter 2)
- [算法作业] Chapter 8 NP-complete problems 课后习题部分证明
- 第三章 练习 知识点 课后作业
- 高编课后作业------第一周-2
- 高级编程技术作业第二周1 第三章课后练习
- 高编课后作业------第一周
- 3第一周课后练习·阅读计划(2)-使用指针来访问私有数据成员
- 高级编程技术作业第四周 第七章课后练习
- python 核心编程课后练习(chapter 3)
- python从入门到实践第三章的课后练习作业
- 高级编程技术作业第三周 第五章,第六章课后练习
- 课堂练习&课后作业
- 蓝欧iOS3G学院OC课后作业练习----实现中等难度通讯录
- 课后作业 10 ---多种引用方法的练习