我需要帮助才能理解我的代码有什么问题(if语句)

时间:2016-06-14 21:23:28

标签: python eclipse if-statement

我不确定我在这段代码中做错了什么,但出于某种原因,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.")

1 个答案:

答案 0 :(得分:1)

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

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

注意,缩进是4个空格。