0

This was a question on my test and I got it incorrect. When I put it in Python the output is None. I don't understand why so it would be great if someone could explain that to me.

def multiply(s,t):
    t*=s
    return
def main():
    d=multiply(2,3)
    print(d)
main()
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
elmo
  • 19
  • 3
  • 4
    Need `return t`. The default return is None. Or even simpler `return s*t` and delete the line above the return. – DarrylG Apr 22 '20 at 22:17
  • @DarrylG what about this question? Write the output of the following program: ``` x = 4 y = 2*x for y in range(x): y-=2 print(y) ``` – elmo Apr 22 '20 at 22:25
  • @elmo--assuming I entered it correctly I get: `-2 -1 0 1` (all on separate lines) . This is because y at the beginning of each loop will be 0, 1, 2 or 3 (regardless of assignments inside the loop). Inside the loop we subtract 2 and print the result creating the output mentioned. – DarrylG Apr 22 '20 at 22:29

1 Answers1

0

You're not returning anything, therefore output of function is None. If you want to return multiply of given integers you can do this like below:

def multiply(s,t):
    return t*s

def main():
    d=multiply(2,3)
    print(d)

main()