Write the output of the following :
>>> x = 8
>>> x = 5
>>> print (x + x)
Answers
Answered by
83
Given code:
>>> x = 8
>>> x = 5
>>> print(x + x)
Output:
10
Explanation:
>>> x = 8
The value 8 is being stored to the variable 'x'.
>>> x = 5
'x' is later on being re-written with 5. So x's current value is 5 and not 8, and 'x' cannot hold two values [8 and 5].
>>> print(x + x)
Since x = 5, x + x = 5 + 5 = 10. Hence, 10 would be the result.
When the same variable is given a new value, the old value will be re-written/updated with the new one and will proceed onto the further steps with the new value.
Answered by
6
To find:
- Output
Step by step solution with Explaination:-
- Intially x= 8
- In line 2, x=5 so value of x is changed to 5
- print(x+x)
- This statement will print the sum of x
- So current value of x is 5
- x+x=5+5=10
Correct Output :
- 10
Similar questions