120k views
1 vote
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 string.
Sample Run
Enter a number: 15.789
Sample Output
The final outcome is: 0.789

1 Answer

1 vote

Answer:

answer for python.

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

decimal_portion = number - int(number)

if decimal_portion < 0:

decimal_portion *= -1

print("The final outcome is: " + str(decimal_portion))

Step-by-step explanation:

The program first prompts the user to enter a number and stores it in the number variable as a floating-point value. Then, the decimal portion of the number is calculated by subtracting the integer portion (obtained through int(number)) from the original number. If the decimal portion is negative, it is multiplied by -1 to ensure that it is positive. Finally, the result is printed with a descriptive message.

User Hilnius
by
7.7k points