Question #101967

Write a program that accepts a number as input, and prints just the decimal portion. Your program must account for negative numbers.

Expert's answer

user_input = input ("Enter the number ")
try:
   val = int(user_input)
   print("Input is an integer number",val,"\nThe decimal value is 0")
except ValueError:
  try:
    val = float(user_input)
    print("Input is a float  number ", val," \nThe decimal value is %.8f"%abs((val-int(val))))
  except ValueError:
      print("No.. input is not a number. It's a string")
LATEST TUTORIALS
APPROVED BY CLIENTS