第一周作业_Chapter 2 课后练习

2-1 简单消息

代码:

favorite_fruit = "apples"

print(favorite_fruit)

运行结果:

2-2 多条简单消息

代码:

favorite_fruit = "apples"
print(favorite_fruit)
favorite_fruit = "pears"
print(favorite_fruit)

运行结果:


2-3 个性化信息

扫描二维码关注公众号,回复: 1046550 查看本文章

代码:

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,显示:


猜你喜欢

转载自blog.csdn.net/cchsblog/article/details/79513984