+ 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"
1 Odpowiedź
+ 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.