M.Sc Python Programming Assignment 2

M.Sc Python Programming Assignments

Assignment 2

Question:

Write a program to check whether the number is even or odd, print out an appropriate message to the user.

Code:

				
					def check_even_odd(number):
    if number % 2 == 0:
        return "even"
    else:
        return "odd"

number = int(input("Enter a number: "))

result = check_even_odd(number)

message = f"The number {number} is {result}."
print(message)

				
			

Output:

				
					Enter a number: 3
The number 3 is odd

				
			
Tech Amplifier Final Logo