Computer Science, asked by sunilmrathod2565, 1 month ago

Write a simple program to accept a value from the user & display whether it is even or odd.
This question is from python program
Sub: Computer

Answers

Answered by anindyaadhikari13
3

Answer:

The given program is written in Python 3.

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

if n%2==0:

print(n,"is even.")

else:

print(n,"is odd.")

Logic:

Logic is very simple. A number is said to be even if it is divisible by 2 whereas a number is said to be odd if it is not divisible by 2.

If the number is divisible by 2, then remainder must be 0.

→ Number divided by 2 leaves remainder = 0

To calculate remainder obtained, the modulo operator is used (%).

So, if n is a number, then remainder on dividing n by 2 will be = n%2

If n%2 is 0, number is even else odd. Using this logic, problem is solved.

Refer to the attachment.

•••♪

Attachments:
Similar questions