Python条件语句

时间:2015-01-04 04:09:45

标签: python-2.7

这就是我做的事情

 money=raw_input("How much money do you have in your bank account?")
     if money >= 700:
         print("you have more or equal to 700")
     else money <700:
         print("you have less than 700")

结果是     500,你有多于或等于700     800,你有多于或等于700

其他短语不起作用

3 个答案:

答案 0 :(得分:0)

确保不要将空格与标签混合。此外,您不需要elseif,因为第一个条件满足>=

money = raw_input("How much money do you have in your bank account?")
if money >= 700:
    print("you have more or equal to 700")
else:
    print("you have less than 700")

答案 1 :(得分:0)

将其更改为:

 money=raw_input("How much money do you have in your bank account?")
 if money >= 700:
     print("you have more or equal to 700")
 else:
     print("you have less than 700")

在其他地方之后不能有任何条件陈述。

或者,您可以这样做:

 money=raw_input("How much money do you have in your bank account?")
 if money >= 700:
     print("you have more or equal to 700")
 elif money <700:
     print("you have less than 700")

请注意,第二个选项是不必要的,因为else意味着money < 700

答案 2 :(得分:0)

您可以使用一行if-else,

在一行中完成此操作
money=raw_input("How much money do you have in your bank account?")
print 'you have more or equal to 700' if money >= 700 else 'you have less than 700'