【问题标题】:python pre-test do while syntax error [closed]python pre-test do while语法错误[关闭]
【发布时间】:2014-10-19 01:41:43
【问题描述】:

这是我的程序,由于某种原因,我一直收到语法错误,请帮我解决这个问题

#Variables
Destination = " "
MilesDest = 0
MPG = 0
GallonCost = 0
GallonsNeeded = 0
GasCost = 0
Syntel = " "

#Below begins Do-While pre-test
while Syntel != "No":
    Syntel = str(input("would you like to run this program?(Yes/No)(Case-Sensitive) "))
    Destination = str(input("Enter the name of your destination: "))
    MilesDest = float(input("Enter the amount of miles between your starting point and your destination: "))
    MPG = float(input("Enter the current MPG your car gets: "))
    GallonCost = float(input("Enter the current cost for a gallon of gas: "))
    GallonsNeeded = MilesDest/MPG
    GasCost = GallonCost*GallonsNeeded
    print("The number of gallons it takes to get to ",Destination, " is ",GallonsNeeded)
    print("The cost of the trip to ",Destination, " is $",GasCost)
 #Salutation
print("Thank you for using my program, good bye")

【问题讨论】:

  • 您在while 语句之前的Syntel = str(input(... 行上缺少两个 右括号。你的缩进很乱,让我们很难对你的帖子说太多,而且你没有包含实际的错误信息。
  • 第二次打印时出现语法错误
  • 再看前一行。您缺少更多右括号。
  • 修复了这个问题,现在在我的第一个打印语句中的“is”之后的引用出现错误
  • 不是交互式调试服务;我已经投票结束您的问题,因为拼写错误对未来的访问者没有用处。

标签: python syntax while-loop


【解决方案1】:

应该是while Syntel != "No":。缺少:

Syntel = 行上还缺少右括号 ))

请注意,一旦更正,程序将永远运行。

【讨论】:

  • 更新:第二次打印时出现语法错误
  • 一般语法错误调试提示:如果您在看起来正常的特定行上遇到语法错误,请查看上一行。
猜你喜欢
  • 2016-05-03
  • 2018-09-23
  • 2014-03-02
  • 2020-03-08
  • 1970-01-01
  • 1970-01-01
  • 2017-09-04
  • 2012-12-09
  • 1970-01-01
相关资源
最近更新 更多