看板 Python 關於我們 聯絡資訊
大家好 小弟在練習一個猜數字的問題 其中一段程式如下 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
HenryLiKing: ==後面拿掉,然後改成is not看看~ 06/28 16:10
nanokevin: If res is not 'h': 還是一樣的錯誤ㄟ 我用python 3.5 06/28 16:12
hung0724: 完整的 code 放 gist 之類的吧 06/28 16:16
HenryLiKing: 我說的是while那行啦~ 06/28 16:18
HenryLiKing: 因為你的==false已經在()後面了才會有錯吧(?)(人腦de 06/28 16:19
HenryLiKing: bug中 06/28 16:19
LessonWang: if 而非 If?! 06/28 16:29
LessonWang: 大小寫有別嗎? 06/28 16:29
AlaRduTP: 有哇 大小寫當然有差... 06/28 16:54
AlaRduTP: https://ideone.com/vaZG7i 06/28 16:54
nanokevin: 真的是大小寫! 在大家面前搞笑了 抱歉!!! 06/28 21:47
darkgerm: while 那是什麼寫法....比較兩字串用 != 比較好 06/30 23:48