我正在尝试让该函数从输入中打印增量坐标,并且在输入后它会跳过或不执行循环。
我尝试将等式简化为准系统,这将无法正常工作。
我在之后放置了一个while循环,以确保它正在跳过/不执行我的循环。
我还尝试过将“和”更改为“或”。
interval = input("Please enter the interval increase for your coordinates: ")
Xstart = input("Start point for X: ")
Ystart = input("Start point for Y: ")
Xstop = input("Stop point for X: ")
Ystop = input("Stop point for Y: ")
while Xstart <= Xstop and Ystart <= Ystop:
print(Xstart, Ystart)
Xstart = Xstart + interval
Ystart = Ystart + interval
证明循环有效:
i = 1
while i < 6:
print(i)
i += 1
我希望它先打印出配对的坐标,然后递增;它完全跳过了循环。
答案 0 :(得分:2)
您需要将每个输入string
强制转换为int
,以便可以评估退出条件Xstart <= Xstop and Ystart <= Ystop
的方式。
interval = int(input("Please enter the interval increase for your coordinates: "))
Xstart = int(input("Start point for X: "))
Ystart = int(input("Start point for Y: "))
Xstop = int(input("Stop point for X: "))
Ystop = int(input("Stop point for Y: "))
while Xstart <= Xstop and Ystart <= Ystop:
print(Xstart, Ystart)
Xstart = Xstart + interval
Ystart = Ystart + interval
用法示例:
Please enter the interval increase for your coordinates: 4
Start point for X: 5
Start point for Y: 6
Stop point for X: 10
Stop point for Y: 10
5 6
9 10