"// running tests" shows "Your code raised an error", but it is not!

I am learning python. In “step-20”:

( workshop-caesar-cipher/step-20 )

I see this error message:

1. Your code raised an error before any tests could run. Please fix it and try again.

while it is not the case. because:

  1. it evens runs my entire code (added some prints in it and tested) and I also run it in an IDLE file without any error.

  2. I reentered the previous step 19. did it again. So i got into step 20 automatically. There, without writing any code, I pressed “Check” button. This error massage appeared again!

What should I do? Any workarounds?

I attach my code here:

def caesar(text, shift):




    if not isinstance(shift, int):

        return 'Shift must be an integer value.'

    

    if shift < 1:

        return 'Shift must be a positive integer.'

    elif shift > 25:

        return 'Shift must be an integer between 1 and 25'

    alphabet = 'abcdefghijklmnopqrstuvwxyz'

    shifted_alphabet = alphabet[shift:] + alphabet[:shift]

    translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())

    #print('Yes!!')

    return text.translate(translation_table)




encrypted_text = caesar('freeCodeCamp', 3)

print(encrypted_text+"\n\ndone!")

Hi @reThinker,

Add a second condition to the if statement that checks if shift is greater than 25. Remember that the logical OR operation in Python is implemented through the or operator.

Also, update the returned message to Shift must be an integer between 1 and 25.

You were asked to add a second condition to the existing if statement and update the message, but instead you created an elif statement.

Happy coding

Hi @dhess
Honestly I ( at the moment ) am not trying to solve the logical error which of course I’ll do next. Now I just want to know why "1. Your code raised an error before any tests could run" which is an interpreter error message, is shown and what is the remedy.

By the way thanks for the reply and helping in logic.
I know you meant this:

    if not isinstance(shift, int):
        return 'Shift must be an integer value.'

    if shift < 1 or shift > 25:
        return 'Shift must be an integer between 1 and 25.'

However, what about interpreter error message?
If it is a bug, where can I issue it?

To see assertion error(s) associated with the message “Your code raised an error before any tests could run”, please open your browser’s console.

@dhess It is already open (Both terminal and console). However there is nothing there because there is no error actually . Please note that IDLE runs the code without any errors. If I had an error, they would type some “Trace back… line…” message for me.

Update: This was not solved because the message was not real. IDLE runs the code without any syntax or interpretation errors. I managed to find a workaround to the environment and close the step.

1. Your code raised an error before any tests could run. Please fix it and try again.

Your original code produced this error in the browser’s console, which is related to the first error message you got when you ran the tests:

After you followed the directions by adding a second condition to the existing if statement and updating the message, your code passed the tests.

IDLE didn’t report an error on your original because there was no error in the code. The “error” was not following the directions in the instructions. The fCC tests are designed to check that you code is implemented as asked.

that 26 =< shift was a syntax error, and is now fixed (I don’t know if deployed), but it was in a part of the test that does not run if you write the correct expression

Thanks for valuable reply to me. I was thinking why my browser’s console does not show any errors with “Trace back…” phrase and line number. Now I (think that) I understand it: That error messages were somewhere but I could not see them. May be I was not allowed (website user restriction) or it was beneath somewhere like my browser’s special debug panes. In the attached screenshot I see that there is an error in the checker. But I had my console pane empty. I even caused an error to see if there is another problem on my side. That intentional error raised a message though.

Anyway, your explanation here:

IDLE didn’t report an error on your original because there was no error in the code. The “error” was not following the directions in the instructions. The fCC tests are designed to check that you code is implemented as asked.

closes my post and makes me satisfied :grinning_face_with_smiling_eyes: I do not have that problem, nor that code now. Keeping forward :saluting_face: