NameError:比较输入时未定义名称“是”

时间:2014-07-02 11:51:18

标签: python

我无法弄清楚为什么会出现错误,指出“是”'未指定。那是什么意思?为什么不赢这项工作? fuelEconomy输入语句有效,函数也可以。出于某种原因,我无法通过while声明接受“是”'输入以执行该功能。

# This program is to calculate fueld economy
def main ():
    fuelEconomy = input ("Do you want to calculate your fuel economy? ")
    print (fuelEconomy)
    while fuelEconomy == Yes:

        Economy ()

    fuelEconomy = input ("Do you want to calculate another?")

#This function is the input and calculation for the program
def Economy ():
        mileage = int (input ("Input mileage "))
        gallons = int (input ("Input gallons used "))
        economy = mileage/gallons
        print ('Your economy is', economy, 'MPG') 

main ()

1 个答案:

答案 0 :(得分:3)

它必须是一个字符串。

while fuelEconomy == 'Yes':

然而,您的代码仍然无法实际运行,因为现在这是一个无限循环,因为fuelEconomy的值不能在循环内发生变化。你可能意味着下一行也在循环内。