Why is the result different. See my code below to help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is the result different. See my code below to help me

a, b = 0, 1 a, b = b, a + b print(a) print(b) a, b = 0, 1 a = b b = a + b print(a) print(b) https://code.sololearn.com/c0SicUF04PdB/?ref=app

6th Apr 2020, 9:05 AM
Kyle
Kyle - avatar
2 Answers
+ 1
a, b = b, a This statement causes swapping values a to b, b to a simultaneously.. So a, b = 0, 1 #a=0,b=1 a, b = b, a + b #a=b=1, b=a+b=0+1=1 so a=1,b=1 a, b = 0, 1 a = b #after this statement b assigned to a, now a and b have same value 1 b = a + b =1+1 So a=1,b=2
6th Apr 2020, 9:10 AM
Jayakrishna 🇮🇳
+ 2
a, b = 0, 1 #a has 0 and b has 1 a, b = b, a + b # a has b which is 1 and b has 0+1 which is 1 print(a) # so it wil print 1 print(b) # so it wil print 1 a, b = 0, 1 # a has 0 and b has 1 a = b # a has 1 b = a + b # b has a+ b which is 1 + 1 that is 2 print(a) # it wil print 1 print(b) # it will print 2 # hope u understood my simple language, folow and message me
6th Apr 2020, 9:28 AM
JAHANGEER LATEEF WANI
JAHANGEER LATEEF WANI - avatar