语法错误无效.也许我的运营商?

Xia*_*iam 0 python

为什么这不起作用?我一直在搞乱我的if语句,它一直给我一个错误并说出无效的语法.也许我只是忘了如何设置运营商.请温柔,我刚刚开始从Java切换到Python.谢谢!

# Create a short program that gets a users age and name

print("Hello there! What is your name?")
myName = raw_input()
print("Okay then %s(myName) how old are you?")
myAge = raw_input()
if myAge < 18
    print("Ah, so you're an adult then!")
else if age >= 18
    print("So you're a kid, huh?")
Run Code Online (Sandbox Code Playgroud)

Ble*_*der 9

你有一些问题:

  • if myAge < 18并且else if age >= 18两者都应该在该行的末尾有冒号.
  • else if应该是elif.
  • 您的年龄比较是倒退的.
  • 您的myAge变量不是整数.这是一个字符串.

这是我如何做到的:

myName = raw_input("Hello there! What is your name? ")
myAge = int(raw_input("Okay then {0} how old are you? ".format(myName)))

if myAge >= 18:
    print("Ah, so you're an adult then!")
else:
    print("So you're a kid, huh?")
Run Code Online (Sandbox Code Playgroud)

如果您使用的是Python 3,请更改raw_inputinput.