Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A student writes if age > 10 and < 20: to test if the age is between and , and gets a SyntaxError. Fix it in two ways.
Each side of and is a full comparison, or use a chain such as 10 < age < 20.
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, go through the solution one step at a time, and check each step against your own.
After and, there must be a full comparison. The part < 20 has no value on its left.
Fix 1. Repeat the variable: if age > 10 and age < 20:.
Fix 2. Use a chained comparison: if 10 < age < 20:.
Both leave out the ends, 10 and 20, because they use < and >.
Log in to join the discussion.
Loading…