當前位置:成語大全網 - 新華字典 - python中循環輸入5門課的成績,如果錄入的成績為負數,則停止錄入並提示錯誤?

python中循環輸入5門課的成績,如果錄入的成績為負數,則停止錄入並提示錯誤?

while(True):

score1 = input('請輸入第壹門課的成績:')

if (int(score1) < 0):

print('成績輸入錯誤,不能小於0')

break;

score2 = input('請輸入第二門課的成績:')

if (int(score2) < 0):

print('成績輸入錯誤,不能小於0')

break;

score3 = input('請輸入第三門課的成績:')

if (int(score3) < 0):

print('成績輸入錯誤,不能小於0')

break;

score4 = input('請輸入第四門課的成績:')

if (int(score4) < 0):

print('成績輸入錯誤,不能小於0')

break;

score5 = input('請輸入第五門課的成績:')

if (int(score5) < 0):

print('成績輸入錯誤,不能小於0')

break;

print('五門課成績分別為:' + str(score1)

? + '分、' + str(score2) + '分、' +

? str(score3) + '分、' + str(score4) +

? '分、' + str(score5) + '分')