+ 5

Why does the code not work?

def multiply(a, b): a * b multiply(6, 9)

13th Aug 2017, 8:37 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
10 Respostas
+ 10
Bcuz Ur aa fagit
13th Aug 2017, 8:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 9
what does return do
14th Aug 2017, 1:55 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 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
13th Aug 2017, 10:39 AM
Sven_m
Sven_m - avatar
+ 7
how do i tell python to show it to me. ive been shouting at it because it doesnt work
13th Aug 2017, 10:48 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 6
why is that very complicated
13th Aug 2017, 11:11 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 4
with print look at my example above
13th Aug 2017, 11:09 AM
Sven_m
Sven_m - avatar
+ 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)
14th Aug 2017, 1:53 PM
m abrate
m abrate - avatar
+ 3
you forgot to return the value of a*b.
13th Aug 2017, 4:08 PM
Michael Petersen
Michael Petersen - avatar
+ 1
b cs ur m um gayy
13th Aug 2017, 8:49 AM
EmptyBox
EmptyBox - avatar
- 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))
14th Aug 2017, 2:42 AM
kamran
kamran - avatar