简体   繁体   English

无效语法:Python 初学者,我的第一个代码

[英]Invalid syntax: beginner at Python, my first code

I get a invalid syntax message at the beginning of input myName.我在输入 myName 的开头收到无效的语法消息。 I don't know why, maybe it's a settings issue, but it highlights the first letter of myName as invalid.我不知道为什么,也许是设置问题,但它突出显示 myName 的第一个字母无效。

Does anyone know why this is happening?有谁知道为什么会这样?

  # This program says hello and asks for my name

print('Hello World')
print('What is your name?' # ask for their name
myName = input()
print('It is good to meet you,' + myName)
print('The length of your name is:')
print(len(myName))
print('What is your age?') # ask for their age
myAge = input()
print('You will be ' + str(int(pyAge) + 1) + ' in a year.')

The issue is that you forgot the closing bracket on line:问题是您忘记了行中的右括号:

print('What is your name?' # ask for their name

it should be:它应该是:

print('What is your name?') # ask for their name

Also, I have a quick tip for the last line.另外,我对最后一行有一个快速提示。 The same output will be produced, if you do:如果您这样做,将产生相同的输出:

print('You will be', int(myAge) + 1, 'in a year.')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM