+ 5
Why does the code not work?
def multiply(a, b): a * b multiply(6, 9)
10 ответов
+ 10
Bcuz Ur aa fagit
+ 9
what does return do
+ 8
You have to tell Python to give a output.
define a output and tell Python to show it to you.
---
def muti (a,b)
result = a*b #thats the definition of the result
print(result) #the call to print
multi (2,2)
>>>4
+ 7
how do i tell python to show it to me. ive been shouting at it because it doesnt work
+ 6
why is that very complicated
+ 4
with print
look at my example above
+ 4
Your fiction should "return" the result, otherwise is almost unuseful..
maybe the easiest solution is
def multiply(a,b):
return a*b
Now you can see the result by
print(multiply(6,9))
or assign the result to another variable among the rest of the code by
prod=multiply(6,9)
+ 3
you forgot to return the value of a*b.
+ 1
b cs ur m um gayy
- 1
The code is not working because a*b must be assigned to a new or existing variable or it must be passed as arguments to a function (function examples return, print e.t.c.)
[when interpreter reaches b in a*b it expects = because may be programmer is trying to do something like this a*=b]
After that the code would work but u won't be able to see the output as there is no print. Below are some working examples
def multiply (a, b) : #best solution
print(a*b)
multiply(6,9)
Or
def multiply (a, b) :
return(a*b)
print(multiply (6,9))
Or
def mul(a, b):
a*=b
return(a)
print(mul(6,9))
Or
def mul(a, b)
c=a*b
return (c)
print(mul(6,9))