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!
submitted by /u/rschubert1122
[link] [comments]
r/learnpython 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! submitted by /u/rschubert1122 [link] [comments]
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!
submitted by /u/rschubert1122
[link] [comments]