我有这个程序:
print('Python accept decrease numbers\n')
initial = int(input('Initial number:'))
ending = int(input('Ending number:'))
decrease = -(int(input('Decrease number:')))
for n in range(initial,ending,decrease):
if (initial < ending):
ending,initial = initial,ending
print (n)
如果初始值小于结束值,我想交换初始值和结束值,以便我可以得到减少值 相反,它什么都不打印出来:
Python accept decrease numbers
Initial number:5
Ending number:50
Decrease number:2
>>>
我错过了什么吗? 感谢。
答案 0 :(得分:0)
只需在for
周期之外移动支票:
print('Python accept decrease numbers\n')
initial = int(input('Initial number:'))
ending = int(input('Ending number:'))
decrease = -(int(input('Decrease number:')))
if (initial < ending):
ending,initial = initial,ending
for n in range(initial,ending,decrease):
print (n)