简体   繁体   English

问题陈述,但我不知道缩进的到底是什么

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

Increment the variable num by 1 post checking the above condition.检查上述条件后,将变量 num 增加 1。 (note that this increment will be outside the if statement, take care of the indentation in order to avoid a scenario of infinite loop) (注意这个增量会在if语句之外,注意缩进以避免死循环的情况)

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. Python 使用缩进来表示嵌套的代码块,在本例中,您的while循环中有一个代码块,由 4 个空格缩进表示。 You then have an if statement when then also needs it's content indented by another 4 spaces.然后你有一个if语句,当 then 还需要它的内容由另外 4 个空格缩进时。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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