为什么这个Python 3代码在运行时会抛出EOFError错误?

时间:2015-05-06 21:44:22

标签: python input

我正在尝试制作一个计算器,将卡路里,体重和锻炼转换为您需要为我的学校项目锻炼的时间。它给出了我在第一行不是注释的错误。

我需要知道为什么它会给我这个错误以及如何修复它。

我还想知道任何其他错误以及如何解决这些问题。

以下是代码:

#Imports
#Variables
#Functions
#Game

calories = input("How many calories or what food item ? : ")
weight = input("How much do you weigh? : ")
exercise = input("Enter your exercise or calories burned per pound per minute : ")

if calories < 0 :
    calories = 0
if weight < 0 :
    weight = 0

if exercise == "sitting" :
    exercise = .009
if exercise == "basketball" :
    exercise = .063
if exercise == "walking" :
    exercise = .019
if exercise == "softball" :
    exercise = .0038
if exercise == "weight training" :
    exercise = .039
if exercise == "jogging" :
    exercise = .063
if exercise == "bowling" :
    exercise = .023
if exercise == "fast biking" :
    exercise = .045
if exercise == "swimming" :
    exercise = .064
if exercise == "slow biking" :
    exercise = .029
if exercise == "ice skating" :
    exercise = .53
if exercise == "soccer" :
    exercise = .076
if exercise == "golf" :
    exercise = .033
if exercise == "sitting" :
    exercise = .009
if exercise == "tennis" :
    exercise = .061
if exercise == "jump rope" :
    exercise = .083

if calories == "big mac" :
    calories = 550
if calories == "large fries" :
    calories = 500
if calories == "large coca-cola" :
    calories = 310
if calories == "salad no dressing" :
    calories = 20

answer = calories / (weight * exercise)
minuteanswer = answer
houranswer = 60 / minuteanswer
dayanswer = 24 / houranswer

print("It will take you " + minuteanswer + " minutes, " + houranswer + " hours, or " + dayanswer + " days to burn off those calories with your chosen execise.")

print("TA-DA!!!!!!")

这是错误:

How many calories or what food item ? : Traceback (most recent call last):
  Line 6, in <module>
    calories = input("How many calories or what food item ? : ")
EOFError

以下是修复所有错误后的更新代码:

#Imports
#Variables
#Functions
#Game

calories = input("What food item ? : ")
weight = input("How much do you weigh? : ")
exercise = input("Enter your exercise : ")

if exercise == "sitting" :
    exercise = 0.009
elif exercise == "basketball" :
    exercise = 0.063
elif exercise == "walking" :
    exercise = 0.019
elif exercise == "softball" :
    exercise = 0.0038
elif exercise == "weight training" :
    exercise = 0.039
elif exercise == "jogging" :
    exercise = 0.063
elif exercise == "bowling" :
    exercise = 0.023
elif exercise == "fast biking" :
    exercise = 0.045
elif exercise == "swimming" :
    exercise = 0.064
elif exercise == "slow biking" :
    exercise = 0.029
elif exercise == "ice skating" :
    exercise = 0.53
elif exercise == "soccer" :
    exercise = 0.076
elif exercise == "golf" :
    exercise = 0.033
elif exercise == "sitting" :
    exercise = 0.009
elif exercise == "tennis" :
    exercise = 0.061
elif exercise == "jump rope" :
    exercise = 0.083
else :
    exercise = .009

if calories == "big mac" :
    calories = 550.0
elif calories == "large fries" :
    calories = 500.0
elif calories == "large coca-cola" :
    calories = 310.0
elif calories == "salad no dressing" :
    calories = 20.0
else :
    calories = 550

answer = calories / (float(weight) * exercise)
minuteanswer = answer
houranswer = 60 / minuteanswer

print("It will take you " ,minuteanswer ," minutes or " ,houranswer ," hours to burn off those calories with your chosen execise.")

print("TA-DA!!!!!!")

1 个答案:

答案 0 :(得分:3)

原始问题的答案是我没有使用正确的IDE而Python版本是2而不是3。