python - 如何在不出现 SyntaxError 的情况下将两个数字相除?
问题描述
"car" = input("Enter the name of the car:")
"gas" = float(input("Enter gas used in gallons:"))
"miles" = float(input("Enter number of miles driven:")
mpg = "miles" / "gas"
print ("Cars Name",car)
print ("Gallons of gas used:,gas)("Number of miles driven:,miles)
print("Miles per Gallon",mpg)
我尝试了多种方法来编写以汽油为单位的英里数,但我一直收到语法错误。我相信这很简单,我只是不知道还有什么可以尝试的
解决方案
"car"
是字符串文字,您不能将某些内容分配给文字。例如,给它赋值意味着什么10
?car
是一个变量。此外,细节在编程中很重要。每个左括号都需要一个右括号。每个引号字符还需要一个成对的引号来关闭字符串。
稍微清理一下,你的程序就可以工作了
car = input("Enter the name of the car:")
gas = float(input("Enter gas used in gallons:"))
miles = float(input("Enter number of miles driven:"))
mpg = miles / gas
print ("Cars Name",car)
print ("Gallons of gas used: ",gas)
print("Number of miles driven: ",miles)
print("Miles per Gallon: ", mpg)
推荐阅读
- sql - 从一个表中选择,其中另一个表的 ID 可以在第三个表中找到
- unit-testing - Django REST Framework 测试:如何将参数传递给 POST 请求。得到错误 400 而不是 201
- javascript - 寻找与此 javascript 代码等效的 python
- csv - 将谷歌电子表格转换为 csv 的问题
- javascript - 在节点中记录当前正在执行的代码行
- sharepoint-online - 在结果搜索查询中使用多个词
- ssh - Terraform 0.11 google_compute_instance 文件配置器 ssh 身份验证失败
- html - 如何在纯 CSS 中制作带有两个(独立)复选框的 HTML 选择字段
- qt - 在使用 QtCreator 运行时指定外部库 PATH
- java - 我想在 Android Studio 中将文件类型转换为 PdfDocument 类型