《Python编程》第二章部分课后练习题

2-2 多条简单消息:

代码:

# 2-2: 多条简单消息 
string = "Today is saturday!"
print(string)

string = "I am doing homework in library!"
print(string)

输出:

Today is saturday!
I am doing homework in library!

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

代码:

# 2-4 调整名字的大小写
name = "Anthony davis"
print(name.lower())
print(name.upper())
print(name.title()) 

输出:

anthony davis
ANTHONY DAVIS
Anthony Davis

2-6 名言2:

代码:

#2-6 名言2
famous_person = 'Kobe Bryant'
quotes = '“I dont want to be the next Michael Jordan, I only want to be Kobe Bryant.”'
message = famous_person + ' once said, ' + quotes		 
print(message)

输出:

Kobe Bryant once said, “I dont want to be the next Michael Jordan, I only want to be Kobe
 Bryant.”

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

代码:

#2-7 剔除人名中的空白:
name = '\n\tKobe Bryant  \n'
print(name)
print(name.lstrip())
print(name.rstrip())
print(name.strip())

输出:



        Kobe Bryant


Kobe Bryant




        Kobe Bryant
Kobe Bryant

2-8 数字8:

代码:

#2-8 数字8
print(int(3.5 + 4.5))
print(int(8.8 - 0.8))
print(4 * 2)
print(int(64 / 8))

输出:

8
8
8
8

2-9 最喜欢的数字:

代码:

#2-9 最喜欢的数字
num = 666
message = 'My favorite number is ' + str(num)
print(message)

输出:

My favorite number is 666

你可能感兴趣的:(《Python编程》第二章部分课后练习题)