我需要帮助来创建一个循环,该循环将要求用户在python中输入两个数字(一个大于另一个),然后继续将1加到小数字上,直到小数字等于大数字为止.
在此期间,我需要它同时打印出数字.
背景知识:我对python还是很陌生,这是我所熟悉的编程类的最后一步,我已经完成了4个任务,这很简单,但这是剩下的一个.
示例:请输入一个小数字:5
请输入一个大数字:10
5、6、7、8、9、10
我希望它如何工作?
var_small = int(raw_input("Please enter a small number : "))
var_large = int(raw_input("Please enter a large number : "))
if var_small > var_large:
print "Try two other numbers, remember that the small number comes first!"
#Here I would re-run the loop
elif var_small < var_large:
var_small +1 until = var_large
对于这个菜鸟问题,我感到很抱歉,希望我能得到答复.
解决方法:
您必须使用while循环将对var_small和var_large的分配合并
var_small = int(raw_input("Please enter a small number : "))
var_large = int(raw_input("Please enter a large number : "))
while var_small > var_large:
print "Try two other numbers, remember that the small number comes first!"
var_small = int(raw_input("Please enter a small number : "))
var_large = int(raw_input("Please enter a large number : "))
while var_small != var_large:
var_small += 1
print var_small, var_large