Dec-22-2019, 06:37 PM
So I'm working through some school material for Higher Computer Science (I'm starting the subject late, with no prior knowledge, so please forgive any amateurish oversight/lack of knowledge). Basically the task I'm doing is simple; making a number-guessing game using a while loop. Anywayyyyyy, the problem I'm facing is that whenever the code hits my 'else' criteria for the loop (in other words, when I guess the right number), nothing happens. I'm just left unable to input anything, do anything, etc.. Could someone please have a look at my code and tell my why this is happening? I should specify, I'm using the Python 3.8 console, not the interpreter. Also, I've put (tab) where I have a tab indent, as it doesn't show in the preview where things are indented.
attempts=0;guess=0;number=random.randint(1,100)
while guess!=number:
... (tab)if int(attempts)<1:guess=input('Feeling lucky? Take a guess!\n');attempts+=1
... (tab)elif int(guess)>int(number):guess=input('Too high! Would you like to try again?\nEnter a number = Yes Alt + F4 = No\n');attempts+=1
... (tab)elif int(guess)<int(number):guess=input('Try a bit higher! Would you like to try again?\nEnter a number = Yes Alt + F4 = No\n');attempts+=1
... else:
... (tab)if int(attempts)<5:print('Congratulations! That only took you '+str(attempts)+' attempts - pretty impressive!')
... (tab)elif int(attempts)<10:print('It took you '+str(attempts)+' tries, but you got there eventually!')
... (tab)else:print('Gosh! '+str(attempts)+' guesses?! It\'s not your lucky day.')
attempts=0;guess=0;number=random.randint(1,100)
while guess!=number:
... (tab)if int(attempts)<1:guess=input('Feeling lucky? Take a guess!\n');attempts+=1
... (tab)elif int(guess)>int(number):guess=input('Too high! Would you like to try again?\nEnter a number = Yes Alt + F4 = No\n');attempts+=1
... (tab)elif int(guess)<int(number):guess=input('Try a bit higher! Would you like to try again?\nEnter a number = Yes Alt + F4 = No\n');attempts+=1
... else:
... (tab)if int(attempts)<5:print('Congratulations! That only took you '+str(attempts)+' attempts - pretty impressive!')
... (tab)elif int(attempts)<10:print('It took you '+str(attempts)+' tries, but you got there eventually!')
... (tab)else:print('Gosh! '+str(attempts)+' guesses?! It\'s not your lucky day.')