Informatics Practices
Find the output of the following code:
x=3
y=x+2
x+=y
print(x,y)
Python Funda
4 Likes
Answer
8 5
Working
x = 3
y = x + 2
xis initialized to 3.yis set tox + 2, which means y = 3 + 2 = 5.
x += y
The += operator adds the value of y to x and assigns the result back to x.
- Current values are:
- x = 3
- y = 5
- Calculation: x + y = 3 + 5 = 8
- Updating
x: x += 5 means x = x + 5 - So, x = 3 + 5 = 8.
print(x, y)
The final values of the variables are:
- x = 8
- y = 5
Hence, the output of the program is:
8 5
Answered By
2 Likes
Related Questions
Explain the difference between syntax error and runtime error with examples.
Identify invalid variable names from the following, giving reason for each:
Group, if, total marks, S.I., volume, tot_strength, #tag, tag, 9a
Find the output of the following code:
x=-2 y=2 x+=y y-=x print (x,y)Find the output of the following code:
a=5 b=2*a a+=a+b b*=a+b print (a,b)