Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A student writes if x = 5: to test if x is 5, and gets a SyntaxError. Why? Write the correct line.
= stores, == compares.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
One equals sign stores a value. Python cannot store a value in the middle of an if line, so it stops with an error.
To compare, we use two equals signs: if x == 5:.
Check. The program below shows True for x == 5, False for x == 6, and then x is five.
Log in to join the discussion.
Loading…