Last answered:

25 Nov 2022

Posted on:

25 Nov 2022

0

Resolved: 5. Conditionals Practice challenge

I don't understand why, but every time I insert a number following the instructions on challenge 3 it runs the else statement saying it is no a number, even though I insert 4 for example.
I added a print screen of my code here, can anyone tell me what I did wrong? Thanks!
The print screen, can anyone tell me why it is wrong?

7 answers ( 1 marked as helpful)
Instructor
Posted on:

25 Nov 2022

0

Hey Valerie,

Thank you for reaching out!

I don't find a mistake in your code right away. Could you please copy-paste it here, so that I also run it on my machine?

Kind regards,
365 Hristina

Posted on:

25 Nov 2022

0

Here it is:
secret_number = 7
guess = input('try to guess the number between 1-10 >>')
if guess.isdigit():
   guess = int(guess)
   if guess == secret_number:
       print ('That\'s it, congrats! You won!')
   elif guess > secret_number and guess <=10:
       print ('That\'s a little bit too high, try again')
   elif guess < secret_number and guess >=1:
       print('That\'s a little bit too low, try again')
   else:
       print ('Out of range')
else:
    print('That\'s not even a number! Are you dumb?')

Thank you! Does this pasting not change the spaces in the code? As I think for some reason that I might have done something wrong there.

Instructor
Posted on:

25 Nov 2022

1

Thank you for your response Valerie!

Indeed the error might be somewhere in the indentation. However, I don't see a difference between the code I've tried and the one you have on the screen, the indentation seems the same to me.
image.png

Could you please try creating a new console (by pressing X next to Console 1/A) and running the code anew?

Below, I've also tried pasting the code I ran on my computer, so that you can also give it a try. Hopefully the indentation is preserved.

secret_number = 7
guess = input('try to guess the number between 1-10 >>')
if guess.isdigit():
    guess = int(guess)
    if guess == secret_number:
        print ('That\'s it, congrats! You won!')
    elif guess > secret_number and guess <=10:
        print ('That\'s a little bit too high, try again')
    elif guess < secret_number and guess >=1:
        print('That\'s a little bit too low, try again')
    else:
        print ('Out of range')
else:
    print('That\'s not even a number! Are you dumb?')

Let me know if any of the above works.

Kind regards,
365 Hristina

Posted on:

25 Nov 2022

0

I closed the console and tried again, same issue...
Than I closed the console again and pasted your code... same issue
I even tried to close both files and console and paste your code ... same issue
At last I decided to completely close spyder and open it again (same issue)

Did it work correctly when you ran it?

Instructor
Posted on:

25 Nov 2022

1

The code from my previous reply should indeed work on your computer - on mine, it runs as expected.
Could I ask you the following:
1. How do you run your code? Do you use the F5 key?
2. Do you put any spaces before or after the number? If yes, then what you should do is run the code, type a number (no other symbols), and then press enter. On your screenshot, I think I see a space right before the number - you'd have to remove it for the program to work.

Hope this helps!

Kind regards,
365 Hristina

Posted on:

25 Nov 2022

0

I wasn't aware of the F5 key to run. I tried without the space (which I didn't notice I added) and now it works, thank you!

Instructor
Posted on:

25 Nov 2022

0

Great, happy to help!

Submit an answer