首页 > 解决方案 > python,字符串,输入和整数,卡在问题的 C 部分

问题描述

#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

输出文件“main.py”,第 95 行 age=2019-birthyear ^ SyntaxError: invalid syntax

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

标签: python

解决方案


你用大写的 Y 写了birthyear。Python 区分大小写。


推荐阅读