Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何取消输入号码?_Python_Loops - Fatal编程技术网

Python 如何取消输入号码?

Python 如何取消输入号码?,python,loops,Python,Loops,我编写了一段代码,其中的说明是“编写一个while循环,打印user_num除以2,直到user_num小于1。user_num的值在循环内部发生变化”。我的代码生成了大部分正确的输出,但它包含了输入值,而输入值不是正确的输出。例如,给定输入值20,我需要输出值10.05.02.51.25.0625,但是,我得到的输出值是20,10.0,5.0,2.5,1.25,这是不正确的答案。有什么建议吗 user_num = int(input()) while user_num >= 1.0:

我编写了一段代码,其中的说明是“编写一个while循环,打印user_num除以2,直到user_num小于1。user_num的值在循环内部发生变化”。我的代码生成了大部分正确的输出,但它包含了输入值,而输入值不是正确的输出。例如,给定输入值20,我需要输出值10.05.02.51.25.0625,但是,我得到的输出值是20,10.0,5.0,2.5,1.25,这是不正确的答案。有什么建议吗

user_num = int(input())

while user_num >= 1.0:

    print(user_num, end='\n',)

    user_num = user_num / 2

切换行的顺序

print(user_num, end='\n',)    
user_num = user_num / 2

切换行的顺序

print(user_num, end='\n',)    
user_num = user_num / 2

只需切换while循环中的行,先除法,然后打印数字。只需切换while循环中的行,先除法,然后打印数字