我想爲x的所有不同值評估x,然後打印結果。 我在這裏做錯了什麼?對於和如果功能
P=3
I=2
L = [2,4,6,8,10]
x = (P * L * y)/ I
for i in L():
if x <= 305:
print "this" + L() + "will not work"
else:
print "this" + L() + "will not work"
我想爲x的所有不同值評估x,然後打印結果。 我在這裏做錯了什麼?對於和如果功能
P=3
I=2
L = [2,4,6,8,10]
x = (P * L * y)/ I
for i in L():
if x <= 305:
print "this" + L() + "will not work"
else:
print "this" + L() + "will not work"
通過您的要求,您應該通過所有的值迭代中L.
嘗試這個代碼
P=3
I=2
L = [2,4,6,8,10]
x=[]
y=?
for i in L:
x.append((P * i * y)/I)
for idx,i in enumerate(x):
if x <= 305:
print "this" + L[idx] + "will not work"
else:
print "this" + L[idx] + "will not work"
你沒有帶指定其將要採取的L
價值,並沒有對x
我猜測,但這種修復你的語法和語義錯誤:
代碼的兩個分支:
P=3
I=2
L = [2,4,6,8,10]
y = 1
for i in L:
x = (P * i * y)/ I
if x <= 305:
print "this", i, "is small enough"
else:
print "this", i, "will not work"
輸出:
this 2 is small enough
this 4 is small enough
this 6 is small enough
this 8 is small enough
this 10 is small enough
嘗試移動'X =(P * L * Y)/ I'到你的'for'循環中。使用'i'而不是'L'。 –
'L()'也不對。 –
'L'是一個列表,而不是一個函數。 –