而在python中循环的单变量语句

问题描述 投票:0回答:1
a = int(input("Give me the first number? "))
b = int(input("Give me the second number? "))
r=a%b

while r:
    a=b
    b=r
    r = a%b

print('The HCF is ', b)

这是我教科书中一个编码问题的解决方案,要求我们,“通过欧几里得除法引理找到一个HCF数”。除了while循环的条件外,我的代码是相同的。

我的条件是:而r == 0课本条件:而r

我的代码给了我一个错误。有人可以解释教科书的情况,因为我还没有看到变量被用作陈述。

python while-loop
1个回答
0
投票

在python中,您几乎可以将每个内置对象用作条件:如果是数字,它将检查该数字是否不同于0如果是列表,字典或集合,它将检查对象是否不为空

© www.soinside.com 2019 - 2024. All rights reserved.