+ 1
How to convert float into integer
If we calculate the sum of two numbers and the results could be either : 16 + 16.2 = 32.2 16 + 16 = 32.0 So how do i give output like 32 if the sum is 32.0 and give output 32.2 if the sum is 32.2 (No round off)
5 Réponses
+ 6
Hi!
Previously, I misunderstood your question. You can add this snippet after you calculated sum variable. I hope this is what you're asking
if sum%1 ==0:
print(int(sum))
else:
print(sum)
+ 2
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner thanks bro
I tried ( sum - int(sum)) == 0
https://code.sololearn.com/c5ODZ9jtz863/?ref=app
+ 1
Sacar How about this code? :-
foo = lambda f: f if f % 1 else int(f)
# I hope that this helps. Happy coding!
+ 1
Delicate Cat and ??
Foo(sum) ??
0
Sacar Yup, foo(num) returns the result.