Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
482 B
3
Indexable
Never
g_list = []
while True:
    n = input('請輸入學生分數(輸入w退出): ')
    if n == 'w':
        print('謝謝填寫')
        break
    else:
        score = int(n)
        g_list.append(score)
        print(f"已加入 {score}")

if len(g_list) > 0:
    total_scores = sum(g_list)
    average_score = total_scores / len(g_list)
    print(f"您共輸入了{len(g_list)}科的成績,您的平均成績為{average_score:.1f}")
else:
    print("沒有輸入任何成績。")
Leave a Comment