-4

my name is Jay and I'm new to python and coding!

How can I convert the results to integer?

# This function adds two numbers
def add(x, y):
    return x + y

# This function subtracts two numbers
def subtract(x, y):
    return x - y

# This function multiplies two numbers
def multiply(x, y):
    return x * y

# This function divides two numbers
def divide(x, y):
    return x / y```

How can I go on? 
Jay
  • 109
  • 8
  • You can use`int()`and put any number in it. – mosc9575 Feb 20 '21 at 19:25
  • Does this answer your question? ["Cast" to int in Python 3.4](https://stackoverflow.com/questions/27244123/cast-to-int-in-python-3-4) – stuckoverflow Feb 20 '21 at 19:26
  • Does this answer your question? [Python float to int conversion](https://stackoverflow.com/questions/6569528/python-float-to-int-conversion) – Yash Feb 20 '21 at 19:27
  • 1
    Note that `int(3.9)` gives `3`. In other words, `int()` truncates the fractional part of a number. Adding `0.5` to your number before converting will make the rounding behave more intuitively (but I think not always correct). – Steven Rumbalski Feb 20 '21 at 19:27
  • Regarding division you would need to be careful since any quotient that is not equal to a integer would be rounded. (given that all input are integers and not floats... Otherwise Stevens comment above would need to be accounted in all cases.) – tbjorch Feb 20 '21 at 19:27
  • 1
    This is a duplicate and could easily be looked up in the documentation – Yash Feb 20 '21 at 19:28
  • Use // for integer division – Mark Tolonen Feb 20 '21 at 19:38

1 Answers1

0

to convert to integer you must use int(x) like this:

def my_function(x,y):
    return int(x / y)
mosc9575
  • 5,618
  • 2
  • 9
  • 32
Kari dime
  • 78
  • 11