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!
New course! Every coder should learn Generative AI!
Try a free lesson
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???

29th Jul 2016, 10:21 AM
Harsh Kanzariya
Harsh Kanzariya - avatar
12 Answers
0
print only show result, would not change value of x In your computer memory, x still 7.
29th Jul 2016, 1:56 PM
jimmy
0
try x=x+3 print(x) it would print the modified value of x
29th Jul 2016, 2:00 PM
sundar
sundar - avatar
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?
29th Jul 2016, 2:06 PM
Harsh Kanzariya
Harsh Kanzariya - avatar
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
29th Jul 2016, 2:18 PM
sundar
sundar - avatar
0
sorry by mistake.. I mean print(x)
29th Jul 2016, 2:23 PM
Harsh Kanzariya
Harsh Kanzariya - avatar
0
yeah. but get enter a no:7 10 7
29th Jul 2016, 2:31 PM
Harsh Kanzariya
Harsh Kanzariya - avatar
0
yeah. but get enter a no:7 10 7
29th Jul 2016, 2:32 PM
Harsh Kanzariya
Harsh Kanzariya - avatar
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
29th Jul 2016, 2:45 PM
sundar
sundar - avatar
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)
18th Aug 2016, 4:27 PM
Angailin Xsanael
Angailin Xsanael - avatar
0
x=o:3
5th Aug 2021, 3:13 PM
Anggi Nurdiah Ayu Priskilia
0
ans 0 and 3
9th Aug 2021, 8:54 AM
Afrina Fatini
- 1
Then it works like the following enter a number: 7 7 10 7 is this what your desired output?
29th Jul 2016, 2:28 PM
sundar
sundar - avatar