简体   繁体   中英

Invalid syntax: beginner at Python, my first code

I get a invalid syntax message at the beginning of input myName. I don't know why, maybe it's a settings issue, but it highlights the first letter of myName as invalid.

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.')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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