Ask 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: 15.789 Output: 0.789 Hint: Make sure to account for negative numbers!

+4
Answers (1)
  1. 28 February, 01:39
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers