为什么这个python3代码在运行时抛出eoferor错误?

2021-04-11 22:51:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个计算器,它能将卡路里、体重和锻炼量换算成我学校项目所需的锻炼时间。它给我的错误下面的第一行,这不是一个评论。在

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

我还想知道其他错误以及如何修复这些错误。在

代码如下:

#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!!!!!!")

错误如下:

^{pr2}$

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

#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!!!!!!")