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
Asked Dec 13, 2019
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

Expert Answer

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

Check out a sample Q&A here.

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

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: write a c++ program that sssign numItems' address to numItemsPtr, then print the shown text followed...

A: Program Code:

question_answer

Q: Define Polymorphism?

A: Polymorphism:A message tells the object to perform a certain method.The same message can produce dif...

question_answer

Q: in c++ I have this working code to read a .dat file #include <iostream>#include <fstream&gt...

A: The student provides the code in c++ language.This program read data from the employee.dat file.All ...

question_answer

Q: True or False: Threads that are part of the same process share the same stack. Briefly explain your ...

A: A thread is the execution unit in a process. A process can range from a single thread to many thread...

question_answer

Q: for c++ for binary tree how would find the longest length?? findlongestlength ()?

A: The function “findlongestlength()” is given with the driver program in C++ is as follows,#include &l...

question_answer

Q: 1:02 PM COmputer ScieNTE QUESTIONS ama answers/ What is... '@ Question: What is the output of the fo...

A: Explanation:The “==” sign in the “if” condition compare the two string reference types “abc” and “xy...

question_answer

Q: Create a query that uses any THREE of the tables (SCHOOL, DEPARTMENT, PROFESSOR, TECHNOLOGY & CO...

A: Here,we have to create all the three tables required for the question-For Department-create table DE...

question_answer

Q: Create a query that uses any THREE of the tables (SCHOOL, DEPARTMENT, PROFESSOR, TECHNOLOGY & CO...

A: Creating the three tables for the given question-For Department-create table DEPARTMENT(DEPARTMENT_N...

question_answer

Q: What is the Big Oh runtime for the following function in terms of n? Show your work.   int recurse(i...

A: Big Oh runtime:Now, the condition if(n==0) makes a comparison and if n = 0, the value 1 is returned....