def function question

Asked 2 years ago, Updated 2 years ago, 76 views

Image 1 is the problem and Image 2 is the correct answer.


def multiples(n, m):
    for i in range(1,m+1):
        print(n*i,end='')

r1,r2,r3,r4=multiples(3,4)
print(r1,r2,r3,r4)
r1,r2,r3,r4,r5=multiples(2,5)
print(r1,r2,r3,r4,r5)


I did it like this, but why isn't it working?

def

2022-09-20 10:22

2 Answers

Answer the meaning and role of return in the function definition. You may find out for yourself as you try to answer that.

I think you pointed out that I didn't use the return function even though I used the definition, so I did not call the function value.

Does return serve as "call function value"? Answer this question.


2022-09-20 10:22

I'll put a spoon on your explanation.

Look at the following example and think about the difference between the given code and the code you made.

a, b, c = 1, 2, 3
print(a, b, c)
>> 1 2 3
d, e, f = 1
print(d, e, f)
>> Traceback (most recent call last):
    d, e, f = 1
TypeError: cannot unpack non-iterable int object


2022-09-20 10:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.