Ask Question
30 January, 12:02

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. 30 January, 12:56
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers