简体   繁体   中英

the problem statement but I don't know what exactly is indented

Increment the variable num by 1 post checking the above condition. (note that this increment will be outside the if statement, take care of the indentation in order to avoid a scenario of infinite loop)

this is the problem statement but I don't know what exactly is indented

I don't know if its correct or not

num = 1
factors=[ ]

while num <= 100: 

    if (num % 10) == 0 :

    factors.append(num)

    num += 1 

    print(factors)

Python uses indentation to indicate nested blocks of code, in this example you have a block of code within your while loop, indicated by the 4 space indentation. You then have an if statement when then also needs it's content indented by another 4 spaces. This would give you the following result:

num = 1
factors = []

while num <= 100: 
    if (num % 10) == 0:
        factors.append(num)
        num += 1 

print(factors)

I think this is the answer to your question

num = 1
factors = []
while num <= 100:
    if (num % 10) == 0:
        factors.append(num)
    num += 1
print (factors)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM