So i found this site called codewars.com and wanted to signup. When i selected my language as python, it gave me a problem to solve:
The code does not execute properly. Try to figure out why.
def multiply(a, b):
a * b
I am not able to figure out why. It executes correctly in PyCharm using python 3.4 when i added print(a*b)
instead of a*b and when i called the function using multiply(2,3)
. The code is also being successfully executed using just the given snippet. It has been given that the above python code is in 2.7 Any ideas?
If it is a function, it needs to return something. Otherwise, running it is kind of useless.
So you probably need to say:
def multiply(a, b):
return a * b
You probably want to read more about functions in Python and when this would make sense (passing by reference, for example). This can be a good starting point: Python functions.
There is no return value, the code will be OK
def multiply(a, b):
return a * b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With