Creating a function to classify numbers as even or odd

Report a typo

Having learned about the 'if' statement in Python, you are now progressing towards a Python function that prints whether numbers from 1 to 10 inclusive are even or odd. For this, fill the blanks in the given code to make use of the concept of a 'while' loop along with the 'if' statement you learned earlier. The output should be in the format 'n is even' or 'n is odd', for each number from 1 to 10 inclusive.

Fill in the gaps with the relevant elements
counter = 1
 counter <= 10:
     counter % 2 == 0:
        print(str(counter) + " is even")
    :
        print(str(counter) + " is odd")
    counter += 1
whileifelse

Create a free account to access the full topic