gpt4 book ai didi

python - 嵌套 for 循环中的错误 (Python)

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:34 25 4
gpt4 key购买 nike

我在以下代码中遇到错误。错误消息是 “错误:检测到不一致的缩进!”

s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0


for j in s:
h=s[j]
print "here is the first loop" +h
for b in a:
c=a[b] #too much indentation
print"here is the second loop" +c #too much indentation
for x in p: #too much indentation
k=p[x]
print"here is the third loop" +k

如果有任何其他错误,如果这里的任何人都可以纠正我,我将非常感激。

谢谢。

/吉拉尼

最佳答案

清理制表符和空格后(您应该只有制表符或只有空格),您需要修复循环:

s = [30,40,50]
a = [5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p = [0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]

for j in s: # within loop j is being 30 then 40 then 50, same true for other loops
print "here is the first loop" + j
for b in a:
print"here is the second loop" + b
for x in p:
print"here is the third loop" + x

否则你会遇到IndexError

关于python - 嵌套 for 循环中的错误 (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1487561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com