0

Why doesn't this code give x+2 answer as we have reassigned the value of x ?

x = 7 x = x + 2 print(x)

25th Dec 2019, 11:52 AM
Castor Reeva
Castor Reeva - avatar
2 odpowiedzi
+ 2
In order to print `x+2` you'll need to assign a string instead of result of arithmetic expression. x=7 # this assign 7 to variable x x=x+2 #this means add 2 to current value of x and assign the result to x. which is similar to x=7+2 x=9 thus you get output 9. as mentioned earlier for printing `x+2` you'll need to quote it and then assign. x="x+2" print(x) if you review your course or search on interbet it'll benifit you more than my answer.
25th Dec 2019, 12:07 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
Thx
25th Dec 2019, 3:47 PM
Castor Reeva
Castor Reeva - avatar