-4
def divide_by_2(number):
   number /= 2

...

def main():
    n = 42
    divide_by_2(n)
    print(n)

The result is 42, not 21. Why is this the case? Thanks in advance.

jojo5
  • 9

1 Answers1

3

You have to return the value from your function

def divide_by_2(number):
   return number / 2 # return the calculation


...

def main(n):
    n = divide_by_2(n)
    print(n)
    >> 21

main(42) # call main with variable number
Meshi
  • 470
  • 4
  • 16