my program x = int(input(" enter a no: ")) print(x) print(x + 3) print(x) then i enter x = 7 output is like enter a no:7 10 7 for both the print(x) why I get different output??? | Sololearn: Learn to code for FREE!

0

my program x = int(input(" enter a no: ")) print(x) print(x + 3) print(x) then i enter x = 7 output is like enter a no:7 10 7 for both the print(x) why I get different output???

7/29/2016 10:21:34 AM

Harsh Kanzariya

12 Answers

New Answer

0

print only show result, would not change value of x In your computer memory, x still 7.

0

try x=x+3 print(x) it would print the modified value of x

0

@jimmy and @sunder my problem is that 1st print(x) prints "enter a no:7" then 2nd print(x)prints only 7. what is causing it?

0

May I know why are you assigning the variable to another variable I mean print =(x) I am sure it wouldn't return anything

0

sorry by mistake.. I mean print(x)

0

yeah. but get enter a no:7 10 7

0

yeah. but get enter a no:7 10 7

0

once again this is problem with solo learn environment if you try in the real python environment it would have worked. Sololearn have its own limitation since its just a simulated python ide

0

the statement 'print(x+3)' doesn't increase a value of the variable x, it only outputs the result of adding x to 3. To change the variable you should write x = x+3 (or x += 3, that's the same)

0

0

ans 0 and 3

-1

Then it works like the following enter a number: 7 7 10 7 is this what your desired output?