找到年齡最大的人,並輸出

#如果是列表:
l1 = [1,2,3,4]
print(max(l1))

#如果是字典法一:
dict1 = {"zhagn":18,"li":20,"wang":22}
value = dict1.values()
print(max(value))
法二:
person = {"li": 18, "wang": 50, "zhang": 20, "sun": 22}
m = 'li'
for key in person.keys():
    if person[m] < person[key]:
        m = key

print(f'{m}\t{person[m]}')

#字符串排序。
str1 = input('input string:')
str2 = input('input string:')
str3 = input('input string:')
print(str1, str2, str3)

if str1 > str2:
    str1, str2 = str2, str1
if str1 > str3:
    str1, str3 = str3, str1
if str2 > str3:
    str2, str3 = str3, str2

print('after being sorted.')
print(str1, str2, str3)

發佈了94 篇原創文章 · 獲贊 1 · 訪問量 2108
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章