+ 5
Logic in thos code?
def func(a,b): s= 0 for i in range(a): for j in range(b): s+=(a+b)%3 return s print(func(3,4))
6 Answers
+ 12
Loop continues 12 times
(a + b) % 3 = 7%3 = 1
so s = 1*12 = 12
+ 10
func(3,4)
So, the innermost statement, s+=(3+4)%3 runs for 12 (3*4) times.
(3+4)%3
= 7%3
= 1
s
= 1+1+1+1+1+1+1+1+1+1+1+1
= 12
s is returned.
12 is returned.
print(func(3,4))
print(12)
12
+ 4
Your print(func(3,4)) command calls the func function with a = 3 and b = 4.
So a+b = 7, and so (a+b)%3 = 1. Your two âforâ loops mean that the s+=(a+b)%3 line is executed 3*4 (=12) times, each time incrementing s by 1.
All this means your function will return 12.
+ 4
AMAN TOMAR Please, as jay told you here https://www.sololearn.com/Discuss/1557917/?ref=app try to not "call" other users in Q&A section... Here there are many users that help then try to wait instead to call determinate users after 5 minutes that you posted the question... If everyone would do it, there would no peace for some users
+ 3
noted KrOW
+ 1
AMAN TOMAR đđđ