How 6 is the output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How 6 is the output?

def f(a): x=a**2 y=0 while x>1: x-=1 y+=2 return y print (f(1)+f(2))

24th Jan 2020, 6:13 AM
Navneet
Navneet - avatar
2 Answers
+ 4
Copy that prog and add lots of print
24th Jan 2020, 6:24 AM
Oma Falk
Oma Falk - avatar
+ 3
If a=1 in f function while loop will executed 0 time ( because 1**2 =1 and 1 = 1). In case a = 2, 2**2 = 4, so loop executes 3 times and y will be 6.
24th Jan 2020, 7:10 AM
Sharofiddin
Sharofiddin - avatar