Course -Python (Videos and MCQs) - chapter -47


#1

I am trying to run the below code , but while submitting here i am getting the the error " Incorrect results for n = 1 " , code is running on jupyter notebook and producing below output, could you please advise.

Print Even Numbers up to n

def print_even(n):
for i in range(0, n):
if (i == 0):
print(’’)
if (i % 2 == 0):
print(i)

print_even(1)
print_even(4)
print_even(5)

o/p -
0

0
2

0
2
4


#2

Hi, Rupesh.
Your solution is almost right, in question it is saying even no, up to n, means n also included.
Kindly check the end condition.
for i in range(0, n+1):

All the best.