46.2k views
4 votes
Python code

Write a program that accepts a number as input, and prints just the decimal portion. Your program should also work if a negative number is inputted by the user. Lastly, write a print statement that states "The final outcome is: ", followed by the decimal portion, and remember to change the final outcome to a string.

Sample: Enter a number: 15.789
The final outcome is:0.789

User Chevone
by
4.9k points

1 Answer

5 votes

Answer:

See below

Note that because of floating point errors, you may not get the exact decimal portion

Step-by-step explanation:

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

dec = abs(n) % 1 # abs function deals with negative numbers also

# to get rid of floating point errors

print("The final outcome is: ", round(dec, 5))

User CryptoKitty
by
4.6k points