Up until now, all the programs you created were static: they always execute all your lines of code. But what if you want to run one line if a number is even, and the other line if a number is odd? Python can also do that for you, if you use the `if` and `else` statement (also known as a conditional statement).
You will use `if` and `else` in a program called `evenorodd.py`. In this program, you will ask the user for an integer and output whether that integer is even or odd!
-!- CODE language-text -!-Enter a number: 7
7 is odd.
Enter a number: 2
2 is even
CodeGrade is your virtual teaching assistant in your Python classroom. You teach, CodeGrade takes care of the rest.
Our 35 built-in fully automatically graded Introduction to Programming assignments are designed especially for middle school and high school coding education, in close collaboration with Harvard-Westlake School (Los Angeles, CA). You can start teaching Python at your school with confidence now. Or, easily scale your classroom with CodeGrade's tools.
Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!