[英]Invalid syntax: beginner at Python, my first code
我在输入 myName 的开头收到无效的语法消息。 我不知道为什么,也许是设置问题,但它突出显示 myName 的第一个字母无效。
有谁知道为什么会这样?
# 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.')
问题是您忘记了行中的右括号:
print('What is your name?' # ask for their name
它应该是:
print('What is your name?') # ask for their name
另外,我对最后一行有一个快速提示。 如果您这样做,将产生相同的输出:
print('You will be', int(myAge) + 1, 'in a year.')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.