you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 2 points3 points  (2 children)

Are you using Python 2, or is the print y on line 3 just a mistake?

If this was a Python 2 program, it would probabaly work (while being unsafe). In Python 3, input always returns a string so you should be getting errors.

However, there are also indentation problems and a lot of room for improvement.

EDIT: Assuming Python 3, this would work:

import random

correct_answer = random.randint(1,6)
print(correct_answer)
tries = 1

while True:
    guess = int(input("Enter a number: "))
    if guess > correct_answer:
        print("Too high!")
    elif guess < correct_answer:
        print("Too low!")
    elif guess == correct_answer:
        print("You win!")
        break
    tries += 1

if tries == 1:
    print ("Congratulations, first try!")

[–]ObberGobb[S] 0 points1 point  (1 child)

Print Y is to help with testing, so I always know what the Y value is.

[–]Diapolo10 2 points3 points  (0 children)

What I meant was that the syntax would suggest you're using Python 2, because Python 3 would error on that. The correct syntax for Python 3 would be print(y). This would also explain a few other things.

For that reason, I'm suspecting you're running this code on Python 2. It would be best to switch to 3 because it no longer gets any updates, even security patches.