231k views
3 votes
We will pass in a value N. Ouput every even value between 0 and N. Tip: you may remember the modulo operator. 10 % 3 returns the remainder of 10 divided by 3. You can use this in a decision to determine whether a number is odd or even. Just think about what makes an even number even and all should become clear!

1 Answer

4 votes

Answer:

def odd_even(N):

for number in range(0, N+1):

if number % 2 == 0:

print(str(number) + " is even")

elif number % 2 == 1:

print(str(number) +" is odd")

odd_even(5)

Step-by-step explanation:

- Create a method called odd_even that takes one parameter, N

- Initialize a for loop that iterates through 0 to N

Inside the loop, check if module of the number with respect to 2 is equal to 0. If yes, print it as even number. If module of the number with respect to 2 is equal to 1, print it as odd number

Call the method

User Barnski
by
5.5k points