day 3-2 python (Odd or Even Exercise)(홀수 또는 짝수)

2023. 2. 22. 00:18개인적인 공부/Python

% 나머지 Modulo 를 이용하서 작성하자

 

Instructions

Write a program that works out whether if a given number is an odd or even number.

Even numbers can be divided by 2 with no remainder.

e.g. 86 is even because 86 ÷ 2 = 43

43 does not have any decimal places. Therefore the division is clean.

e.g. 59 is odd because 59 ÷ 2 = 29.5

29.5 is not a whole number, it has decimal places. Therefore there is a remainder of 0.5, so the division is not clean.

The modulo is written as a percentage sign (%) in Python. It gives you the remainder after a division.

 

e.g.

6 ÷ 2 = 3 with no remainder.

therefore: 6 % 2 = 0

5 ÷ 2 = 2 x 2 + 1, remainder is 1.

therefore: 5 % 2 = 1

14 ÷ 4 = 3 x 4 + 2, remainder is 2.

therefore: 14 % 4 = 2

Warning your output should match the Example Output format exactly, even the positions of the commas and full stops.

 

Example Input 1

43

Example Output 1

This is an odd number.

Example Input 2

94

Example Output 2

This is an even number.

e.g. When you hit run, this is what should happen:

 

# 🚨 Don't change the code below 👇
number = int(input("Which number do you want to check? "))
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

나의 값

# 홀 짝 나타내기 Odd or Even

# 🚨 Don't change the code below 👇 건들지 마라
number = int(input("Which number do you want to check? "))
# # 🚨 Don't change the code above 👆

# #Write your code below this line 👇

if (number % 2) == 1:
    print("This is an odd number")
else:
    print("This is an even number")