为什么这if,elif和if语句不适用于raw_input

时间:2019-12-01 13:25:05

标签: python-2.7

name = raw_input("What is your name? ")
quest = raw_input("What quest do you chose?, 1 for slaying a dragon, 2 for defeating the evil wizard and 3 for killing the kraken ")
if quest == 1
  quest == "so you want to slay a dragon."
   elif quest == 2
    quest == "do you have something against wizards, relax im joking"
     elif quest = 3
      quest == "have you got a boat, better jet a submarine?"
      else quest = "so you have no quest, hm... in that case GET OUT OF MY SWAMP"

print quest

它一直给我这个错误:

文件“ python”,第3行     如果任务== 1                 ^ SyntaxError:语法无效

1 个答案:

答案 0 :(得分:0)

  1. “ ==”是逻辑运算符,您不能使用它为任务分配值。
  2. 放置ifif条件后,应放置“:”
  3. 缩进python是至关重要且必不可少的。
  4. 打印是您需要括号来打印任务的一种方法
  5. 检查下面的代码段,它是您的代码的有效版本

name = raw_input("What is your name? ")
quest = raw_input("What quest do you chose?, 1 for slaying a dragon, 2 for defeating 
the evil wizard and 3 for killing the kraken\n")

if quest == "1":
   quest = "so you want to slay a dragon."
elif quest == "2":
   quest = "do you have something against wizards, relax im joking"
elif quest == "3":
   quest = "have you got a boat, better jet a submarine?"
else:
   quest = "so you have no quest, hm... in that case GET OUT OF MY SWAMP"

print(quest)

如果这有助于您将其标记为问题的答案!