0
Why is my code not working?
8 Réponses
+ 6
David Lahu ,
> the *asterik* in the function header is *required*, since there are *3 arguments* when calling the function.
> if we use a *list* or *tuple* (with the numbers as members) when calling the function, asterik is not required.
+ 4
Because you didn't return value
+ 1
The problem with the code is that the function doesn’t print the value of total to the screen nor does it return the value of total that can then be printed to the screen
Here is how to fix it:
Option 1, return total and then use print():
def multiple(*numbers):
total = 1
for number in numbers:
total = total * number
return total #returns the value of total
print(multiple(1,2,3)) #prints total to the screen
Option 2, automatically prints the value of total in the function itself:
def multiple(*numbers):
total = 1
for number in numbers:
total = total * number
print(total) #prints the value of total
multiple(1,2,3) #doesn't need print()
+ 1
Your code is working, it is displaying the value of 120. Please provide a detailed explanation of what you want to do.
+ 1
Danish Zubair Their code used to not work, since it didnt return anything.
0
You put an extra ) at the end
Hope this helps
0
When I delete it, it says no output
0
There's no need for the asterik in the function definition.