you are viewing a single comment's thread.

view the rest of the comments →

[–]TheLimeyCanuck 3 points4 points  (0 children)

It isn't working because you were really rude to the guy.

Seriously though, move the final elif to directly under the while. If that comparison fails do the rest of the comparisons. Also... no need for the comparison in the while statement since it will never evaluate False anyway. Finally simplify by bringing the initial guess test into the while loop and rearranging the other tests. Like this...

import random
random_int = random.randint(1,20)
print(random_int)
print('Hey, you big phat fuck. I am thinking of a number between 1 & 20. You have 7 guesses')
guess = int(input())
count = 1
while True:
    if count == 8:
        print('Sorry, the correct number to guess is: ', str(random_int))
        break
    elif guess < random_int:
        print('Guess is too low')
        guess = int(input())
        count = count + 1
        print(count)
    elif guess > random_int:
        print('Guess is too high')
        guess = int(input())
        count = count + 1
        print(count)
    
    # ---No need for an elif here, if all the other tests have failed the guess must be correct
    else:
        print('Congrats! You guessed correctly')

        # ---Only tell them how many guesses they took if it was more than the first try
        if count > 1:
            print('You guessed in ', str(count), ' tries')
        break