Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Wetherbee
1,467 Pointseven_odd function
Need help please...
Thank you in advance!
John
def even_odd(number):
while True:
number = input(" ")
number = number / 2
if number = float
print("False")
continue
if number = int:
print("True")
continue
2 Answers
Kent Åsvang
18,823 PointsOkay, so based on the code you have provided you are either looking for this :
def even_odd(number):
return True if number % 2 == 0 else False
Or you are looking for this :
def even_odd():
number = input("Please enter a number and I'll tell you if it is an even number :")
return True if number % 2 == 0 else False
Now, I see you have a while loop inside you procedure. I don't see the reason for this programmatically. The way you have done it though - make the while loop run forever with no way to exit. So you have to either change your "continues" to "breaks", or you have to check if the user typed "quit" instead of a keyword. Like so :
def even_odd():
while True:
number = input("Enter a number and I will tell you if it is an even number, Or type 'quit' to quit : ")
if number == "quit":
break;
elif number % 2 == 0 :
return True
else:
return False
Hope this helped you somewhat.
John Wetherbee
1,467 PointsThanks very much Kent!