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 trial
Jack Cummins
17,417 PointsPlease help make my program better! Even if it already has answers, please still give suggestons! Thank you so much!
I will give out a best answer and upvotes for good suggestons! Thank you! My code is below:
import random
import sys
def even_odd():
number = random.randint(1, 10)
if number % 2 == 0:
print("You got an even number! It was {}!".format(number))
else:
print("You got an odd number! It was {}!".format(number))
while True:
try:
times_called = int(input("How many times do you want to run the even_odd function? "))
except:
print("Sorry, you have to type a number.")
sys.exit()
while times_called > 0:
even_odd()
times_called -= 1
want_quit = input("Press enter or return to keep going. Press 'Q' to quit. ").lower()
if want_quit == "q":
sys.exit()
else:
continue
Also, would you please tell me how to put snapshots of my code into my posts?
Thanks! Jack
1 Answer
Brendon Butler
4,254 PointsLooks pretty good to me. Python isn't my forte, so it may be possible to optimize this code further. But it looks pretty well written as is!
Jack Cummins
17,417 PointsJack Cummins
17,417 PointsThank You Brendon Butler ! Make sure to tell me if you have any suggestons!
Happy Coding! Jack