Click here to Skip to main content
15,178,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Have the function MathChallenge (num) check whether every single number in the passed in parameter is even. If so, return the string true, otherwise return the string false. For example: if num is 4602225 your program should return the string false because 5 is not an even number

What I have tried:

Python
m = int(input("Enter number"))
if m % 2 == 0:
    print(m,"is an even number")
else:
    print(m,"is an odd number")
Posted
Updated 1-Dec-21 2:38am
v2
Comments
Richard MacCutchan 1-Dec-21 5:33am
   
check whether every single number in the passed in parameter is even. If so, return the string true, otherwise return the string false.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Read the question carefully: you have to create a function - which you haven't done - and return a string which gives the result - which you haven't done.
Read your last set of course notes, and it should be easy for you to set up the function and go from there.
   
You program works: it produces the expected output. (thanks, Richard) is able to distinguish between even and odd inputs. You have just to wrap the logic in a function returning a boolean value.
Something like
Python
def MathChallenge(num):
  # your logic here 

m = int(input("Enter number"))
if MathChallenge(m):
    print(m,"is an even number")
else:
    print(m,"is an odd number")
   
v5
Comments
Richard MacCutchan 1-Dec-21 7:34am
   
Not according to the instructions in the question. :)
CPallini 1-Dec-21 7:38am
   
True.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900