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!

Respuesta :

Answer:

Explanation:

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)

Answer:

x=float(input("Enter a number: "))

sub=(x-int(x))

print(sub)

Explanation:

Got it right