![](/img/trans.png)
[英]Python | Selenium | Keeps outputting page source rather than what I see when I manually inspect element
[英]This code keeps outputting different messages than what I have assigned
Question = input("How much money did Kingsman make this weekend?:")
if Question > "10000000":
print("Wow! What an opening!")
elif Question >= "5000000" <= "9000000":
print("Hey! Not a bad start!")
elif Question < "5000000":
print("Are you happy with this result?")
如果我說 Kingsman 賺了 4,000,000 美元,它會輸出電影票房超過 1000 萬美元的信息,但真正奇怪的是,當我輸入 $1 時,它會輸出電影票房少於 500 萬美元的信息(應該如此)和當我 go 高達 4,000,000 美元時,它顯示 output 的價格不到 5 百萬美元(應該如此)。 出於某種原因,相同數字的輸出(在本例中為 400 萬)從“哇。多么開放”到“你對這個結果是否滿意”,我不明白為什么。
另外,我不確定"elif Question >= "5000000" <= "9000000":"是否正確。 我想說的是,當電影的收入在 500 萬到 900 萬之間時,它應該顯示消息“嘿!不錯的開始!”
當您可能應該比較整數時,您正在比較字符串。
elif Question >= "5000000" <= "9000000":
不正確。
它應該是這樣的:
elif 5000000 <= int(Question) <= 9000000:
您甚至可以通過將 int() 放在 input() 上,將輸入轉換為 integer 格式。
Question = int(input("How much money did Kingsman make this weekend?: "))
然后您可以將 output 與整數進行正確比較。
if Question > 10000000:
您的參數將不再有問題。 您的程序響應不同的原因是因為您將字符串輸入與其他字符串輸入進行比較。 它仍然進行比較而沒有拋出任何錯誤的原因是因為它的 unicode 值。
前任。 程序:
print('apple' == 'Apple')
print('apple' > 'Apple')
print('A unicode is', ord('A'), ',a unicode is', ord('a'))
程序 Output:
False
True
A unicode is 65 ,a unicode is 97
這只是為了參考為什么它允許您比較 2 個字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.