+ 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.

22nd Aug 2016, 5:12 PM
Harman Grewal
Harman Grewal - avatar
7 odpowiedzi
+ 2
ans is print all even numbers from 2 to 10
15th Jan 2023, 9:47 AM
saklen Mujawar
saklen Mujawar - avatar
0
that code print 2,4,6,8 and 10.
22nd Aug 2016, 5:59 PM
Adrian Manrique
Adrian Manrique - avatar
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.
22nd Aug 2016, 6:02 PM
Adrian Manrique
Adrian Manrique - avatar
0
yeah i know but the answer is worded incorrectly
22nd Aug 2016, 6:05 PM
Harman Grewal
Harman Grewal - avatar
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.
12th Jun 2022, 3:49 PM
Prateek Jakhar
0
for i in range(10): if not i%2==0: print(i+1) Answer: 2 4 6 8 10
13th Nov 2022, 10:24 AM
Etoke Theodore
Etoke Theodore - avatar
- 7
that code should print -> 1 3 5 7 9
23rd Aug 2016, 3:07 PM
Dibyendu Das
Dibyendu Das - avatar