+ 5
WRONG ANSWER FOR QUESTION IN PYTHON COURSE
For the python course there is a question that asks: for i in range(10): if not i%2==0 print(i+1) What does this print? The answer that is told is that it "prints out all even numbers between 2 and 10. However the correct answer should be it prints out all even numbers between and INCLUDING 2 to 10, or all even numbers between 1 and 11.
7 odpowiedzi
+ 2
ans is print all even numbers from 2 to 10
0
that code print 2,4,6,8 and 10.
0
1℅2 ==0 is false but the if is negative so false and false is true then i plus 1 is equal to 2. so print 2. when i is 3 print 4 , when i is 5 print 6, when i is 7 print 8 and finally when i is 9 print 10.
0
yeah i know but the answer is worded incorrectly
0
Simplified solution:
not 0 % 2 == 0 - False
not 1 % 2 == 0 - True
1+1 = 2
not 2 % 2 == 0 - False
not 3 % 2 == 0 - True
3+1 = 4
not 4 % 2 == 0 - False
not 5 % 2 == 0 - True
5+1 = 6
not 6 % 2 == 0 - False
not 7 % 2 == 0 - True
7+1 = 8
not 8 % 2 == 0 - False
not 9 % 2 == 0 - True
9+1 = 10
Hence, it will print the even values from 2 to 10.
0
for i in range(10):
if not i%2==0:
print(i+1)
Answer:
2
4
6
8
10
- 7
that code should print ->
1
3
5
7
9