+ 1

Why would this be like this?

Basically i understand most of this i made it to kind of practice amd further understand it but when i put a=a+4 why would it not add the original a = 2 and 4 and begin counting by 6? https://code.sololearn.com/c3KdGxs52I10/?ref=app

5th Apr 2017, 12:50 AM
Seth T
Seth T - avatar
18 odpowiedzi
+ 16
a = 2 # a is 2 print(a+2) # a is 2 but it prints 4 a = a+4 # a is 2+4 so a is 6 print(a+2) # a is 6 but it prints 8 a = a+4 # a is 6+4 so a is 10 print(a+2) # a is 10 but it prints 12 a = a+4 # a is 10+4 so a is 14 ...
5th Apr 2017, 1:21 AM
Jafca
Jafca - avatar
+ 16
Thanks for the Tick ✔ 👍
5th Apr 2017, 1:28 AM
Jafca
Jafca - avatar
+ 15
Can you tell us what sequence you want? Do you want 2,4,6,8... or 4,8,12.. or 6,10,14...?
5th Apr 2017, 1:13 AM
Jafca
Jafca - avatar
+ 4
yea u made it pretty clear @Jafca. still have doubts @seth?
5th Apr 2017, 1:22 AM
Edward
+ 3
ah ok. honest mistake. we are here to help
5th Apr 2017, 1:24 AM
Edward
+ 2
"a" gets the value of a + 4. since "a" starts with 2, a gets the value of 2 + 4. so "a" gets the value of 6. if u continue.... a=a+4 // a is 10 a=a+4 // a is 14 a=a+4 // a is 18 and so on
5th Apr 2017, 12:54 AM
Edward
+ 2
oh lol im not sure
5th Apr 2017, 1:02 AM
Edward
+ 2
oh
5th Apr 2017, 1:02 AM
Edward
+ 2
cause you are printing a + 2. change it to just print a
5th Apr 2017, 1:03 AM
Edward
+ 2
so you want to start at 4 and then count by 4s?
5th Apr 2017, 1:07 AM
Edward
+ 2
but if its already counting by 4s, i dont understand your problem
5th Apr 2017, 1:11 AM
Edward
+ 2
because then that would be counting by six. which means you would need a = a + 6.
5th Apr 2017, 1:21 AM
Edward
+ 2
omg im dumb, the a+4 part just means its going to add a by 4, saying a = a+4 through me off because i assumed it would add that 4 to the a and count by the new a. thanks tho
5th Apr 2017, 1:23 AM
Seth T
Seth T - avatar
+ 2
Yep thanks you guys!
5th Apr 2017, 1:25 AM
Seth T
Seth T - avatar
+ 1
no see thats what im saying if you run the code it still counts by 4s not 6s
5th Apr 2017, 12:57 AM
Seth T
Seth T - avatar
+ 1
but what if i want it to start at 4 without makimg a=4?
5th Apr 2017, 1:04 AM
Seth T
Seth T - avatar
+ 1
exactly BUT without changing a=2 to a=4
5th Apr 2017, 1:09 AM
Seth T
Seth T - avatar
+ 1
its not my problem, my problem is why doesnt a=a+4 not cause the original a to add with 4 and instead of counting by 4s count by 6s. sorry you kinda confused me, i want it to count by 4s and it does but why isnt it counting by 6s like it technically should. a+4 would be 2+4 which = 6 which means a would now = 6 therefore it shouldnt count by 4s anymore it should begin with 4 then continue to add with 6s. 4 10 16 22 ...
5th Apr 2017, 1:17 AM
Seth T
Seth T - avatar