- 1

Let's say I don't want the user input's output, if it were a whole number, to be x.0, how would I do that?

Seems a bit confusing I know. Let me show you: user_input=float(input("Enter a number")) user_input=12 a=user_input + 12 print(a) If I'm not mistaken the output would be 24.0, is there a way to get rid of the .0 part? I don't want to get rid of it if it's not a whole number, just if it is a whole number.

24th Aug 2016, 1:34 AM
Darth Vador
Darth Vador - avatar
5 Answers
0
i C programing u can use %d.0 yo undo the .0 i think in python u can use the same think to undo the .0
24th Aug 2016, 4:34 AM
John
0
Why make it a float in the first place?
24th Aug 2016, 11:17 AM
Mahmoud Nassif
Mahmoud Nassif - avatar
0
Because I need it to be defined as a number and, if necessary, have a decimal. I'm trying to make a calculator and I've succeeded but I think the .0 at the end is a bit ugly if unnecessary. It's not that big of a deal, I was just wondering.
24th Aug 2016, 7:26 PM
Darth Vador
Darth Vador - avatar
0
try this? user_input=input("enter num") //input 12 total= input +12 if total = float(total) print (float(total)) else print(total)
24th Aug 2016, 7:53 PM
John
0
==*
24th Aug 2016, 7:56 PM
John