我如何获得一个整数以保持自身除数?

时间:2018-10-11 01:19:55

标签: python-3.x while-loop

我已经尝试了所有方法,但遇到了麻烦。任何帮助都将是有帮助的:)我需要输出的是10.0、5.0、2.5、1.25、0.625,我的问题是我无法让程序在0.625处停止。

'user_num = 20'
while user_num  > 10:
    user_num = user_num/2.0
print(user_num)

1 个答案:

答案 0 :(得分:3)

简单地改变您的不平等标准怎么办?

user_num = 20
while user_num > 0.625:
    user_num /= 2.0  # equivalent to doing user_num = user_num/2.0
    print(user_num)

哪些印刷品

10.0
5.0
2.5
1.25
0.625