首页 > 解决方案 > 如何在不出现 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)

我尝试了多种方法来编写以汽油为单位的英里数,但我一直收到语法错误。我相信这很简单,我只是不知道还有什么可以尝试的

标签: pythondebugging

解决方案


"car"是字符串文字,您不能将某些内容分配给文字。例如,给它赋值意味着什么10car是一个变量。此外,细节在编程中很重要。每个左括号都需要一个右括号。每个引号字符还需要一个成对的引号来关闭字符串。

稍微清理一下,你的程序就可以工作了

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)

推荐阅读