我正在瀏覽 SO,但找不到解決問題的方法,所以我發了一個帖子。
我嘗試使用具有多個條件(至少 3 個)的 If 陳述句創建一個 For 回圈,但它不起作用,我無法繞開它......我嘗試了很多東西,但沒有任何接縫可以作業。
這是我的代碼,經過簡化,因為在我的實際代碼中,a、b、c 和 d 的值是隨機的:
a=[1]
b=[2]
c=[3]
d=[0,1,2,3,4,5,6,7,8]
for i in d:
if d>a and\
d>b and\
d>c:
print("OK")
else:
print("not OK")
但無論我嘗試什么,我總是得到這個輸出:
not OK
not OK
not OK
not OK
not OK
not OK
not OK
not OK
not OK
謝謝您的幫助
uj5u.com熱心網友回復:
你的意思是這個:
a = 1
b = 2
c = 3
d = [0, 1, 2, 3, 4, 5, 6, 7, 8]
for i in d:
if i > a and i > b and i > c:
print("OK")
else:
print("not OK")
not OK
not OK
not OK
not OK
OK
OK
OK
OK
OK
uj5u.com熱心網友回復:
固定代碼:
a=1
b=2
c=3
d=[0,1,2,3,4,5,6,7,8]
for i in d:
if i>a and\
i>b and\
i>c:
print("OK")
else:
print("not OK")
輸出
not OK
not OK
not OK
not OK
OK
OK
OK
OK
OK
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/427547.html
