Hy ...我只是在學python。我做了這樣一個程序:missbehaviour的「OR」在Python中
guess = raw_input("please input something...");
while (guess != 'h'):
guess = raw_input("pleae input something again....");
print(guess);
print("Thanks...");
那麼...上面的程序運行良好。但是,當我把「OR」的猜測後=這樣的「H」:
guess = raw_input("please input something...");
while (guess != 'h') or (guess != 't'):
guess = raw_input("pleae input something again....");
print(guess);
print("Thanks...");
上述程序在while循環運行下去。那裏發生了什麼?我以爲環路將I輸入可以是H或T之後
當'guess'是'h'時,顯然不會't';作爲繼續的條件之一是'guess!='t'',它滿足繼續循環的條件。 – metatoaster