我需要帮助来了解我的代码(if 语句)出了什么问题



我不确定我在这个代码中做错了什么,但出于某种原因,Eclipse 一直告诉我 if 语句很糟糕。 我不知道为什么,当我看例子时,它对我来说看起来很好。

penny = .01
nickel = .05
dime = .1
quarter = .25
print("Enter how many coins you want to use to make a dollar.")
e_pen = int(input("Enter the amount of pennies you want: "))
e_nic = int(input("Enter the amount of nickels you want: "))
e_dim = int(input("Enter the amount of dimes you want: "))
e_qua = int(input("Enter the amount of quarters you want: "))
doll = float((e_pen * penny) + (e_nic * nickel) + (e_dim *dime) + (e_qua * quarter))
if doll > 1    # every conditional needs a : per the answer below
    print("The total value is greater than 1 dollar.")  # notice the indentation
else          # same here
   print("Try again.")

如果语句需要冒号和正确的缩进,请参阅:

if doll > 1:
    print("blah")
else:
    Print ("Try again")

请注意,缩进为 4 个空格。

最新更新