习题 7:更多的打印


现在做一批习题,这个习题是巩固之前学到的。


ex7.py

# 玛丽有只小羊羔。
print("Mary had a little lamb.")
# 它的羊毛是白色的,像“雪”一样。(格式化(雪))
print("Its fleece was white as {}.".format('snow'))
# 不管玛丽去哪里。
print("And everywhere that Mary went.")
# 打印10次 "."
print("." * 10)     # what'd that do?(这是做什么的?)

end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"

# 注意结尾的逗号。尝试移除它,看看会发生什么。
# watch that comma at the end. try removing it to see what happens
print(end1 + end2 + end3 + end4 + end5 + end6, end=' ')
print(end7 + end8 + end9 + end10 + end11 + end12)

结果:

 

 常见问题

为什么要用一个叫 'snow' 的变量?

其实不是变量,而是一个内容为单词 snow 的字符串而已。变量名是不会带引号的。

猜你喜欢

转载自www.cnblogs.com/llr211/p/11454538.html