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

Python

eden ohana
eden ohana
1,786 Points

How bad am i?

Tried to do what Kenneth suggested at the end of the numbers game videos...


code: import random

def game():

guess = random.randint(1, 10)

while True:

    print ("Think of a number between 1 to 10, i will try and guess it.")
    yn = raw_input("Do you have the number? press y to continue > ")
    if yn != "y":
        break
    answer = (raw_input("Is you number is {} ? yes/no > ".format(guess)))
    if answer == "yes":
        print("Great, I was right!")
        break
    elif answer == "no":
        print("Uh, Maybe next time.")
        break

game()

def replay():

while True:

    replay = raw_input("Do you want to try again? press y to continue > ")
    if replay == "y":
        game()
    else:
        break

replay()

end of code.

1 Answer

Before I study your code I will first point out that Python is real picky on spaces and indenting; you might try removing the space after print in this line: print ("Think of a number between 1 to 10, i will try and guess it.")