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 trialNicholas Anstis
2,095 PointsPython Basics excersise
Here's that question :
Make a while loop that runs until start is falsey. Inside the loop, use random.randint(1, 99) to get a random number between 1 and 99. If that random number is even (use even_odd to find out), print "{} is even", putting the random number in the hole. Otherwise, print "{} is odd", again using the random number. Finally, decrement start by 1.
I can't figure it out by myself i need help from you guys
import random
secret = random.randint(1, 99)
start = 5
while False:
guess = int
def even_odd(num):
if guess == secret:
print("{} is even".format(secret)
else:
print("{} is odd".format(secret)
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
return not num % 2
else:
if start == False:
break
2 Answers
Steven Parker
231,248 PointsHere's a few hints:
- don't change the even_odd function that was provided.
- put your while loop at the bottom of the file
- make sure your while is checking the value of start
- create the random number inside the loop
- make use of even_odd in an if statement to test the random number
- after your if/else and prints, remember to reduce start
I'll bet you can get it now without an explicit spoiler. But post again if you need more help.
Nicholas Anstis
2,095 PointsOk thanks a lot. Ill try to figure that out :D !