[英]Convert positive input into negative number
start = int(input("Please enter starting number"))
end = int(input("Please enter ending number"))
amount = int(input("Please enter the amount to count"))
for i in range(start,end,amount):
print(i)
I want the number from the amount variable to be converted into a negative number so that I can reverse range()
.我希望将数量变量中的数字转换为负数,以便我可以反转range()
。
You want to negate it only if the start is greater than the end.只有当开始大于结束时,您才想否定它。
if start > end:
amount = -amount
Or you can tuck that right into the range()
call:或者您可以将其直接放入range()
调用中:
for i in range(start, end, -amount if start > end else amount):
我不确定这是否是您真正想要的,但是要将金额转换为负数,您只需键入以下内容:
amount = amount * -1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.