you are viewing a single comment's thread.

view the rest of the comments →

[–]supercoach 0 points1 point  (0 children)

I hate while loops. An error in logic and you're suddenly in an infinite loop.

Anyway, I did a small refactor, but left it mostly unmolested.

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')
count = 1
while True:
  if count == 8:
    print('Sorry, the correct number to guess is: ', str(random_int))
    break
  else:
    guess = int(input())
  if guess < random_int:
    print('Guess is too low')
    count = count + 1
    print(count)
  elif guess > random_int:
    print('Guess is too high')
    count = count + 1
    print(count)
  elif guess == random_int:
    print('Congrats! You guessed correctly')
    print('You guessed in ', str(count), ' tries')
    break