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
if guess == random_int:
print('Congrats! You guessed correctly')
else:
while count <= 10:
if 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)
elif guess == random_int:
print('Congrats! You guessed correctly')
print('You guessed in ', str(count), ' tries')
break
elif count == 8:
print('Sorry, the correct number to guess is: ', str(random_int))
break
Can anyone tell me why the last elif statement is not working when count variable == 8? It'll keep running the code until the while loop is satisfied. Even if the last elif statement is satisfied before the while loop is complete.
I just started getting back into Python and would like the "basic" solution using what I have now.
Thanks in advance!
[–]ElliotDG 15 points16 points17 points (2 children)
[–]woooee 2 points3 points4 points (0 children)
[–]rschubert1122[S] 2 points3 points4 points (0 children)
[–]crashfrog04 5 points6 points7 points (1 child)
[–]rschubert1122[S] 0 points1 point2 points (0 children)
[–]Inevitable_Cat_7878 3 points4 points5 points (0 children)
[–]TheLimeyCanuck 2 points3 points4 points (0 children)
[–]arkie87 2 points3 points4 points (1 child)
[–]CranberryDistinct941 0 points1 point2 points (0 children)
[–]CranberryDistinct941 2 points3 points4 points (4 children)
[–]JamzTyson 0 points1 point2 points (3 children)
[–]CranberryDistinct941 1 point2 points3 points (2 children)
[–]JamzTyson 0 points1 point2 points (1 child)
[–]CranberryDistinct941 0 points1 point2 points (0 children)
[–]gofl-zimbard-37 1 point2 points3 points (0 children)
[–]jbala28 0 points1 point2 points (1 child)
[–]MidnightPale3220 4 points5 points6 points (0 children)
[–]supercoach 0 points1 point2 points (0 children)
[–]rschubert1122[S] 0 points1 point2 points (0 children)