How do I get the whole number when using "/" operator in python

Viewed 33

Below is my code for a problem on leetcode:

for i in range(len(nums)):
    ans =0   
    ans+=nums[i]
    for j in range(i+1,len(nums)):
        realans=0
        ans+=nums[j]
        realans= ans/k
        if isinstance(realans,int):
            return True
    return False

I want to check if the variable realans is an integer or not upon division. But even if it is an integer it takes the value of 7.0 ex: 14/2 = 7.0

If I add // instead of /, for the values where I get 7.3 it converts to 7 making the logic wrong. How can I fix this? Just to make sure, I don't want the number to be rounded off.

0 Answers
Related