[問題] 字串的比較與invalid syntax 求助

看板Python作者 (明日幸福今日修)時間8年前 (2017/06/28 16:03), 編輯推噓5(507)
留言12則, 6人參與, 最新討論串1/2 (看更多)
大家好 小弟在練習一個猜數字的問題 其中一段程式如下 res = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.") while (res is 'c')==False: If res=='h': 請用戶輸入 h 或 l 或 c 然後 用戶輸入的str 會放入res 我的疑問是下面的invalid syntax該如何修正呢 (我不知道問題在哪) If res=='h': ^ SyntaxError: invalid syntax 此關於如果輸入不為c 我的寫法是 while (res is 'c')==False: 我好奇有其他的寫法嗎? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 50.39.175.20 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1498637033.A.3EF.html

06/28 16:10, , 1F
==後面拿掉,然後改成is not看看~
06/28 16:10, 1F

06/28 16:12, , 2F
If res is not 'h': 還是一樣的錯誤ㄟ 我用python 3.5
06/28 16:12, 2F

06/28 16:16, , 3F
完整的 code 放 gist 之類的吧
06/28 16:16, 3F

06/28 16:18, , 4F
我說的是while那行啦~
06/28 16:18, 4F

06/28 16:19, , 5F
因為你的==false已經在()後面了才會有錯吧(?)(人腦de
06/28 16:19, 5F

06/28 16:19, , 6F
bug中
06/28 16:19, 6F

06/28 16:29, , 7F
if 而非 If?!
06/28 16:29, 7F

06/28 16:29, , 8F
大小寫有別嗎?
06/28 16:29, 8F

06/28 16:54, , 9F
有哇 大小寫當然有差...
06/28 16:54, 9F

06/28 16:54, , 10F

06/28 21:47, , 11F
真的是大小寫! 在大家面前搞笑了 抱歉!!!
06/28 21:47, 11F

06/30 23:48, , 12F
while 那是什麼寫法....比較兩字串用 != 比較好
06/30 23:48, 12F
文章代碼(AID): #1PKsBfFl (Python)
文章代碼(AID): #1PKsBfFl (Python)