Python 3: Recursivley find if number is even

Posted by pythonhack on Stack Overflow See other posts from Stack Overflow or by pythonhack
Published on 2012-11-09T03:35:12Z Indexed on 2012/11/09 5:00 UTC
Read the original article Hit count: 160

Filed under:
|
|

I am writing a program that must find if a number is even or not. It needs to follow this template. I can get it to find if a number is even or not recursively (call function and subtract 2, base case zero), but I am having a hard time following this template, based on how the isEven function is called in the main function. Any help would be greatly appreciated.

Write a recursive function called isEven that finds whether a number is even or not:

def isEven()
#recursivley determine whether number is even or not

def main():
    number=int(input(“Enter a number : “))
    if (isEven(number)):
         print(“Number is even”)
    else:
         print(“Number is not even”)

main()

Thank you! Appreciate it.

© Stack Overflow or respective owner

Related posts about python

Related posts about recursion