如何运行如下,给出if和else语句?
我等待肯定回复
def run():
a=10
b=20
c=30
if a==15 & b==20 & c==30:
print('a is diff')
else a==10 & b==20 & c==30:
print ('same')
else a==15 & b==40 & c==30:
print('a is diff')
答案 0 :(得分:1)
您需要elif
,而不能使用两个else
。
此外,else
一无所获。
你应该替换&
bij and
。
def run():
a = 10
b = 20
c = 30
if (a == 15) and (b == 20) and (c == 30):
print('a is diff')
elif (a == 10) and (b == 20) and (c == 30):
print ('same')
elif (a == 15) and (b == 40) and (c == 30):
print('a is diff')
else:
print('Other')
答案 1 :(得分:0)
您应该使用elif
代替else
答案 2 :(得分:0)
我已经更正了您的代码,假设您希望代码示例返回“相同”。我已将else
替换为elif
,将按位运算符&
替换为and
。
def run():
a=10
b=20
c=30
if a==15 and b==20 and c==30:
print('a is diff')
elif a==10 and b==20 and c==30:
print ('same')
elif a==15 and b==40 and c==30:
print('a is diff')
run()