您的位置:首页 > 其它

第一周作业_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,显示:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: