python、字符串、输入和整数,停留在问题的C部分

python、字符串、输入和整数,停留在问题的C部分,python,Python,输出 文件main.py,第95行 年龄=2019年出生 ^ SyntaxError:无效语法 我被困在C部分,我需要从2019年减去用户输入生日。当我做的是年龄=2019年生日时,它说的是语法错误。如何命名变量名 您用大写Y写了生日。Python区分大小写。您缺少生日=赋值后的第二个右括号。你已经输入了。。。有两个左括号和一个右括号 编辑:您更改了原始问题文本。我看到的唯一遗留问题是,您的生日=和年龄=行以空格开头。当我删除空白空间时,它的效果与希望完全一样。 编辑2:根据您的评论: #Exe

输出 文件main.py,第95行 年龄=2019年出生 ^ SyntaxError:无效语法


我被困在C部分,我需要从2019年减去用户输入生日。当我做的是年龄=2019年生日时,它说的是语法错误。如何命名变量名

您用大写Y写了生日。Python区分大小写。

您缺少生日=赋值后的第二个右括号。你已经输入了。。。有两个左括号和一个右括号

编辑:您更改了原始问题文本。我看到的唯一遗留问题是,您的生日=和年龄=行以空格开头。当我删除空白空间时,它的效果与希望完全一样。

编辑2:根据您的评论:

#Exercise 5
#a Ask the user for a birth year using the prompt: birthyear? (include a space after the ?)
#b Convert the user input to an integer
#c Subtract the user entered birthyear from 2019
#d Convert the result of the previous line and the user entry to strings using the str() function
#e Display the following using the + concatenator in a print statement (note the punctuation and spacing):
#f It has been [converted result of line 5c]! years since your birthyear in [converted user entry]!
#g Hence, if user entered 2010, display:
#h It has been 9! years since your birthyear in 2010
#i Next, display the words: You were born in the year:
#j Display the converted user entered birthyear vertically, one digit at a time.
#k For example, for 2010 display (ignore the # signs):
#2
#0
#1
#0  
birthyear=int(input('birthyear? '))
age=2019-birthyear
所以这是正确的。但是,如果命令行输入无效,请执行以下操作:

>>> b=int(input('birthyear? '))
birthyear? 23
>>> b
23

这将导致一个类似于您所看到的错误。

欢迎使用StackOverflow。请按照您创建此帐户时的建议,阅读并遵循帮助文档中的发布指南。适用于这里。在您发布MCVE代码并准确指定问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中,并重现您指定的问题。您发布的代码看起来运行得很好。避免外部链接,但在问题中应将作业的相关部分和代码作为格式正确的文本包含在内。错误似乎不在代码的显示部分。此外:使用“复制和粘贴”在此处显示代码和错误消息,以避免输入错误。提示:请检查type2019和TypeBirthYears。请使用您现在拥有的确切代码及其生成的准确完整的错误消息更新您的问题。从所有的编辑和对以前打字错误的回答来看,很难判断发生了什么。我已经改变了这一点,只是说年龄不确定。我尝试了这个代码,它对我有效:birthyear=intinput'birthyear?“年龄=2019-出生年份打印年龄这是我将得到的。我该如何解决这个问题?生日?回溯上次的最新调用:文件main.py,第94行,在birthyear=intinput'birthyear'ValueError:以10为底的int的文本无效:“b”当我在左边添加括号时,我将得到这个结果。生日?回溯最后一次调用:文件main.py,第94行,在b=intinput'birthyear'中ValueError:基数为10的int的文本无效:“b”
>>> b=int(input('birthyear? '))
birthyear? boo!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'boo!'