Exercise 5
Write a program in Python language that asks the user to enter an integer number 'n' and display whether this number is even or odd.
Solution
1 2 3 4 5 6 7 8 9 10 |
# Ask user to enter a value of n n = input("Type value of the integer n: ") # Convert n to integer n = int(n) # Test if n is even or not if(n%2 == 0): print("The number '", n, "' typed is even") else: print("The number '", n, "' typed is odd ") |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Solution Exercise 5: test the parity of a number in python”