當前位置:成語大全網 - 新華字典 - python列表題?

python列表題?

思路就以學分為key ,語文 數學 英語 分別為value構造三個字典 以key查找value 然後輸出結果

list1 = [1, 2, 3, 4]

list2 = [98, 67, 89, 80]

list3 = [100, 90, 83, 62]

list4 = [90, 98, 100, 82]

dic1 = dict(zip(list1, list2))

dic2 = dict(zip(list1, list3))

dic3 = dict(zip(list1, list4))

key = int(input('請輸入學生學號:'))

# 判斷學生學號是否存在

if key in list1:

# 語文

language = int(dic1[key])

# 數學

mathematics = int(dic2[key])

# 英語

english = int(dic3[key])

# 總和

total = language + mathematics + english

print('語文:' + str(language) + ' 數學:' + str(mathematics) + ' 英語:' + str(english) + ' 總分:' + str(total))