V
V
Vadim2312017-09-18 21:01:08
Facebook
Vadim231, 2017-09-18 21:01:08

How to make if the number was not an integer, gave out -1 in response?

def get_row_len(row, col, cell_index):
    if (cell_index / row) - col == float:
        return -1

I need that if the answer is in action (cell_index / row) - col was an integer, if it is not an integer it writes -1
I wrote that, what's wrong here?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexey Tutubalin, 2019-06-03
@Kennius

These are exactly the application settings, it may be worth adding domains like site.ru and www.site.ru or any other domains if used
or recreate it

S
SolidMinus, 2017-09-18
@SolidMinus

You are comparing some number with a type, nothing bothers you?

def get_row_len(row, col, cell_index):
    A = (cell_index / row) - col
    if round(A) != A:
        return -1

A
Astrohas, 2017-09-18
@Astrohas

is_float = lambda x: bool(x % 1 )
def get_row_len(row, col, cell_index):
    if is_float(cell_index / row - col):
        return -1

or right away
def get_row_len(row, col, cell_index):
    if (cell_index / row - col) % 1:
        return -1

T
Twelfth Doctor, 2017-09-18
@verdex

def get_row_len(row, col, cell_index):
    a = (cell_index / row) - col
    if int(a) != a:
        return -1

A
Alexander, 2017-09-18
@kentuck1213

def get_row_len(row, col, cell_index):
    if type((cell_index / row) - col)) == float:
        return -1
//////////
isinstance(1.1, float)
>>> True

S
Stepan Krapivin, 2017-09-18
@xevin

is_integer() method

a = (cell_index / row) - col
if a.is_integer():
  return a
else:
  return -1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question