Python教材第二章部分习题

教材:《Python编程 从入门到实践》

2-2:多条简单消息

# 2-2 multiple simple messages
msg = "Hello!"
print(msg)
msg = "My name is Maxwell"
print(msg)

输出:

Hello!
My name is Maxwell


2-4:调整名字的大小写

# 2-4 playing around with cases
name = "JiN aIr GreeNwings roGue"
print(name.lower())
print(name.upper())
print(name.title())

输出:

jin air greenwings rogue
JIN AIR GREENWINGS ROGUE
Jin Air Greenwings Rogue


2-6:名言2

# 2-6 quote 2
famous_person = "Tal Ben Shahar"
message = '"Common sense is not that common."'
print(famous_person + " once said: " + message)

输出:

Tal Ben Shahar once said: "Common sense is not that common."


2-7:删除人名中的空白



2-8:数字8

# 2-8 number 8
print(2 + 6)
print(9 - 1)
print(2 * 4)
print(int(24 / 3))

输出:

8
8
8
8

猜你喜欢

转载自blog.csdn.net/qq_35783731/article/details/79477507
今日推荐