# Odd even ChallangePython CodingTell user to input a 3 digital number ONLYUse a WHILE LOOP to ask the user for :1) Any 3 digit number - if the number is NOT three digits, you need to use the TRY EXCEPT2) Use calculations to determine if the number is odd or even. 3) With the 3 digit number, add all the individual numbers together.

Question
8 views

Odd even Challange

Python Coding

Tell user to input a 3 digital number ONLY
Use a WHILE LOOP to ask the user for :
1) Any 3 digit number - if the number is NOT three digits, you need to use the TRY EXCEPT
2) Use calculations to determine if the number is odd or even.
3) With the 3 digit number, add all the individual numbers together.

check_circle

Step 1

Following is the python program that takes as input from user a number and makes sure a number is a three-digit number, then it checks if the number is even or odd and finally prints sum of all digits:

Approach:

• Use the while loop to make the number entered by the user is three digits only.
• Inside try block prompt user to enter a three-digit number.
• Check the length of the number entered by the user and if it is other than three-digit numbers then raise ValueError exception.
• Inside try block also check if the number is odd or even and print the sum of all digits of the number.
• Use the except block to print the statement in case of an exception.

Step 2

Code:

#while loop to make sure user enter three-digit number only

while True:

#try block

try:

#prompt user to enter a three-digit number

num=int(input('Enter a three-digit number only: '))

#check if number of digits in number is 3 or not

if len(str(num))==3:

#condition to check if number is even

if num%2==0:

print('even')

#if number is not even then print odd

else:

print('odd')

#variable to count sum of all digits

sum=0

...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in