19th Jun 2023, 9:37 AM
Amirhossein
Amirhossein - avatar
8 Antworten
+ 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.
19th Jun 2023, 12:01 PM
Lothar
Lothar - avatar
+ 4
Because you didn't return value
19th Jun 2023, 10:01 AM
A͢J
A͢J - avatar
+ 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()
19th Jun 2023, 10:08 AM
Nikola Markov
+ 1
Your code is working, it is displaying the value of 120. Please provide a detailed explanation of what you want to do.
21st Jun 2023, 9:43 AM
Danish Zubair
Danish Zubair - avatar
+ 1
Danish Zubair Their code used to not work, since it didnt return anything.
21st Jun 2023, 9:46 AM
Nikola Markov
0
You put an extra ) at the end Hope this helps
19th Jun 2023, 9:43 AM
David Lahu
0
When I delete it, it says no output
19th Jun 2023, 9:46 AM
Amirhossein
Amirhossein - avatar
0
There's no need for the asterik in the function definition.
19th Jun 2023, 9:48 AM
David Lahu