Ask Question

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!

+3
Answers (1)
  1. 30 November, 15:44
    0
    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)

    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers