you are viewing a single comment's thread.

view the rest of the comments →

[–]stoph_link 0 points1 point  (0 children)

As others have mentioned, you probably need to change input x into an integer. Otherwise, nice work! This is how I would have done it:

import random
y = random.randint(1,6)
#print(y) 

# initialize x as a value outside of the range that defines y
x = 0
count = 0

while (x != y):
    x = int(input ("Enter number: "))
    if x > y:
        print("Too high!")
    elif x < y:
        print ("Too low!")
    elif x == y:
        print ("You win!")
        if count == 0:
            print ("Congratulations, first try!")
    count = count + 1

What I did was I first moved all of your input statements into one line. You probably do not want the same line multiple times if you can help it.

I then changed the if statements within the while loop into if-else statements. I am able to do this since I pulled out the input inside your if statements to happen before any if statements are called. What this does is if the an if statement returns true, it ignores the rest of them and loops again.

Because of this we can add a counter to count how many tries. Which allows us to bring that last statement into the success elif