Ask Question
8 September, 05:24

2.4 Code Practice: Question 2 Write a program that accepts a number as input, and prints just the decimal portion. Example: Enter a number: 15.789 Output: 0.789 Hint: Make sure to account for negative numbers!

+3
Answers (1)
  1. 8 September, 08:19
    0
    Let's code it using python. We can take care of the negative number by placing an absolute function at the end. Basically the decimal part is calculated by subtracting the integer part from the original input number

    def decimal_print (number):

    int_part = int (number)

    decimal_part = number - int_part

    return abs (decimal_part)
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “2.4 Code Practice: Question 2 Write a program that accepts a number as input, and prints just the decimal portion. Example: Enter a number: ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers