why my code is showing "if" part output and "else" part output together? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why my code is showing "if" part output and "else" part output together?

team_a = int(input("write how many goal did team A:\n")) team_b = int(input("write how many goal did team B:\n ")) team_c = int(input("how many goal did team C :\n ")) if team_a > team_b and team_a > team_c: print("TEAM 'A' IS WIN") if team_b > team_a and team_b > team_c: print("TEAM 'C' IS WIN") if team_c > team_a and team_c > team_b: print("TEAM 'C' IS WINNTER") else: print("I DON'T KNOW") # if team a is win then compiler is showing "team_a is win and "i don't know"

14th Mar 2019, 2:05 PM
Ali Baba
Ali Baba - avatar
1 Answer
+ 5
The else statement is binded to the last if statement. If team_a wins, the first if statement is true and print("TEAM 'A' IS WIN") is executed. At the same time, team_c > team_a and team_c > team_b is false, hence the else statement executes and "I DON'T KNOW" is printed. To "fix" your code, use elif instead of separate if statements.
14th Mar 2019, 2:16 PM
Hatsy Rei
Hatsy Rei - avatar