You have two problems:
- You need to use
== for comparison tests, not = (which is for variable assignment).
if needs to be lowercase. Remember that Python is case-sensitive.
However, you should be using elif and else here since no two of those expressions could ever be True at the same time:
Swansea=2
Liverpool=2
if Swansea < Liverpool:
print("Swansea beat Liverpool")
elif Swansea > Liverpool:
print("Liverpool beat Swansea")
else:
print("Swansea and Liverpool drew")
Though using three separate if's won't generate an error, using elif and else is much better for two reasons:
- Code clarity: It is a lot easier to see that only one of the expressions will ever be
True.
- Code efficiency: Evaluation will stop as soon as an expression is
True. Your current code however will always evaluate all three expressions, even if the first or the second is True.
<,>,and==, there is only one possible answer. A number can't be<and>and==another number. So it would make more sense to you theif x > y: .... elif y > x: ... else: ....construct. It makes more sense semantically and also only executes one of the blocks each time not 3.