好吧,所以我是新來的python,並試圖學習如何編碼。今天我遇到了一個我不明白的問題。因此,該代碼按預期執行,並打印三個數字中最大的一個,而不管最大數字的位置。如果聲明沒有評估所有條件並執行
if num1 >= num2 and num3:
print(num1, 'Is the greatest number!')
elif num2 >= num3 and num1:
print(num2, 'Is the greatest number!')
else:
print(num3, 'Is the greatest number')
但是,如果我改變elif的語句是:
elif num2 >= num1 and num3:
print(num2, 'Is the greatest number!')
即使NUM3是最大else語句將不執行,它會顯示NUM1 NUM2或較大的數量。
嘗試使用'num1 = 2','num2 = 1'和'num3 = 10'運行,代碼的第一個代碼段將不起作用。它會打印「(2,'最大的數字!')」。 – Jae