+ 1
whats wrong with this code??
Its around a week since i started learning python from javascript I know this is a stupid question but why does this print up to 40 should it have printed as long as y is less than 20 https://code.sololearn.com/cKxRim5Z1MsB/?ref=app
6 Respostas
+ 4
When y is 20, it will print 40 as you have asked to print y*2, not y, if you were trying to make it count up by twos it would look like this:
def num(y):
while y < 20:
y+=2
print(y)
num(2)
I’m not sure if this fixes your problem
+ 4
That's because you use print(y*2) which outputs the incremented y value multiplied by 2;
3 -> 6
4 -> 8
...
20 -> 40
+ 3
It's because y*2 does not change the value of y
+ 3
Thanks for the summary Eligijus
+ 2
I think it is: Because you increased y before you printf(y*2)
def num(y):
while y < 20:
print(2*y)
y+=1
num(2)
+ 1
Got it,Thanks you all :-)