When I divide the (n+1)/2 it gives me the values in float form even though they are a whole number is there anyway to turn only the floats ending in .00 into integers.Code
I tried to find whether a number was even or odd by adding 1 to the number then dividing the sum by 2 if it is an integer it would’ve been an odd number and if it had decimal places it would of been even. But after the running my code it gave me all the numbers in float form stopping me from being able to run my check for an integer as all my values where floats giving me the return of Even for all numbers.
>Solution :
So, to answer your question directly, if x is a float use:
if x.is_integer():
...
However, if you just want to know if a number is even, don’t use division! then use the mod operator:
is_even = n % 2 == 0