2_5_zen
名人名言,用字典最好
1 name1 = "winston churchill" 2 zen1 = "The farther backward you can look,the farther forward you will see." 3 print(f'{name1.title()} once said,"{zen1}"') 4 name2 = "william faulkner" 5 zen2 = "Don't bother just to be better than your contemporaries or predecessors.Try tobe better than yourself." 6 print(f'{name2.title()} once said,"{zen2}') 7 name3 = "einstein" 8 zen3 = "Imagination is more important than knowledge.Knowledge is limited.Imagaination encircles the world." 9 print(f'{name3.title()} once said,"{zen3}') 10 dict1={name1:zen1,name2:zen2,name3:zen3} 11 for key in dict1: 12 #print(type(key)) 13 print(f'{key.title()} once said,"{dict1.get(key)}"')
key是字符串类型,所以可以使用title方法