Why does my code not print values divisible by 2?
There are a couple different reasons this may happen, so go through the checklist below:
- Did you indent your code properly? Remember that Python uses indentation (2 spaces per indentation level) to denote blocks of code.
- Is there a colon after your for loop and if statement? Leaving this out causes a syntax error.
- What value are you printing inside of your if statement if the number is divisible by 2? If you’re printing the list name, that’s not quite right - print the variable you just checked.
- Did you use
==to check if a number is divisible by 2? Remember that
=is used to assign value, so that’s not what we use in an if statement.