Answer to Question #101967 in Python for s

Question #101967
Write a program that accepts a number as input, and prints just the decimal portion. Your program must account for negative numbers.
1
Expert's answer
2020-01-30T04:41:54-0500
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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS