python - 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 时,它说语法错误。如何命名变量名?
解决方案
你用大写的 Y 写了birthyear。Python 区分大小写。
推荐阅读
- docker - Visual Studio、Docker 和 Docker-Compose 实践
- c# - Azure 函数 5 和 EF Core 5 无法加载文件或程序集 > Microsoft.Extensions.DependencyInjection.Abstractions
- react-native - 无法使用 react-native 运行玩笑:TypeError:无法解构“未定义”或“空”的属性“仪器”
- javascript - Firebase 自定义验证电子邮件模板
- javascript - 嵌套异步/等待使用
- reactjs - 如何在 React 中用鼠标绘制矩形?
- php - Laravel - 任务调度或队列?
- templates - VBA Word 365 显示工作组模板供用户选择模板以创建文档
- javascript - 如何在反应使用状态字符串中添加新行
- java - MapStruct/映射接口字段/java