Python Forum
I don't know what's wrong with this code [Python Console]
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't know what's wrong with this code [Python Console]
#1
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.')
Reply


Messages In This Thread
I don't know what's wrong with this code [Python Console] - by H0M1C1D4L_P1G - Dec-22-2019, 06:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  In Console,Python anna17 0 214 Mar-23-2024, 08:24 PM
Last Post: anna17
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 494 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Something wrong with my code FabianPruitt 5 872 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,588 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,269 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,821 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,582 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Python Flask Realtime system printout (console) ffmpeg jttolleson 3 2,958 Apr-18-2022, 06:39 PM
Last Post: jttolleson
  Wrong code in Python exercise MaartenRo 2 1,541 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,637 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020