我有一个将Degrees Minutes Seconds转换为Decimal Degrees的脚本,我在使用while循环时遇到了麻烦:
lat_dir = raw_input("For your latitude coordinates, please enter N for northern hemisphere or S for southern hemisphere: ")
while lat_dir <> "N" or lat_dir <> "S": #check input to confirm lat_dir = N or S
lat_dir = raw_input("Please enter N for northern hemisphere or S for Southern hemisphere: ")
我也在东西方使用了一个非常相似的while循环,它给了我同样的问题。我希望它循环,直到给出正确的输入,但如果我使用这样的while循环,它不会破坏循环,无论如何。我也尝试了一个if循环,只要你给出一个“N”或“S”就可以工作,否则以后会在脚本中出错。否则我的代码运行完美。
答案 0 :(得分:2)
你应该使用而不是或在你的支票中。
while lat_dir <> "N" and lat_dir <> "S":