练习7、8、9:打印,打印,打印

不断的练习,查错,不懂的地方翻阅资料

print("练习7:更多打印")

#打印句子
print("solo had a little lamb.")
print("Its fleece was white as %s." %'snow')
print("And everywhere that Mary went.")
print("." * 10) #打印出10个点

#字符串给变量
end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"
#打印
print(end1 + end2 + end3 + end4 + end5 + end6 ,end = " ")  # end = "" 表示下一行打印时不换hang;引号中间可加入空格、字符等
print(end7 + end8 + end9 + end10 + end11 + end12)
print("." * 10)

结果:

习题8:

print("习题8:打印,打印")

#变量指向格式化的字符串
formatter = "%r %r %r %r"

print (formatter %(1,2,3,4))#格式化的字符串被分别赋值1234
print(formatter %("one","two","three","four"))
print(formatter %(True,False,False,True))
print(formatter %(formatter,formatter,formatter,formatter))
print(formatter %(
    "I had this ting.",
    "That you could type up right.",
    "But it did't sing.",
    "so I said goodnight."
))

结果:

习题9:

print("习题9:打印,打印,打印")

days = "Mon Tue Wed Thu Fri Sat Sun"
#\n 表示换行
months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"  

#打印出句子
print("Here are the days:",days)
print("Here are the months:",months)

#三引号适用于多行句子打印
print(
"""
there's somthing going on here.
with the three double-quotes.
we'll be able to type as much as we like.
Even 4 lines if we went,or 5,or 6.
"""
)

结果:

猜你喜欢

转载自www.cnblogs.com/aszeno/p/9146002.html