Scientific Computing with Python - Python Environment & Replit

I found this course on freecodecamp recently, and have already completed Arithmetic Formatter.

My query isn’t about code or failing tests, it’s about the FCC environment. This is what I see when I go into a challenge:

However, across several posts, I’ve seen talk of using a multiple file environment, of importing various packages, and basically what sounds like Replit.

Even before seeing those I had created my own replit to do this code as it’s a nicer environment than the one in my screenshot above.
my dev code

But now I’ve just found this post describing creating a replit project from freecodecamp starter code.

I can see no mention of any of this in the pages for ‘Scientific Computing with Python’, so now I’m just really confused about what is expected of me, how I’m supposed to work, and how it all fits together. The only thing I think know for sure is that I’ll have to run the final code against the tests back in the main FCC env and submit there. Or do I?

I copied the code from my own replit project into the main FCC one, and created a world of pain when some tabs replaced spaces (or vice versa). It took me forever to spot what was going on (it’s the whole white-space-as-syntax thing that put me off learning Python for years, but not looking to open that can of worms right now!).

Could someone advise on how I’m expected to go about this please?

It used to run on Replit but now it runs on a platform hosted on the fcc website. You can code on Replit or VScode locally or your preferred software, but you’re correct, you will need to paste it into the editor here to run the tests and pass.

Copy/paste your code should basically work fine. You can turn off the instructions panel, Console and Preview to give you a wide space to troubleshoot your code and there are vertical lines that will help with indentation.

Do you have a specific example of how it went wrong?

My biggest problem with the FCC env is the lack of error messages. If I code in VS Code or Replit and make a syntax error, I get the real error message and line number, but in FCC I just get “Your code raised an error before any tests could run. Please fix it and try again.”, which is utterly useless. Why is it hidden?

There does seem to be a problem with white space in the FCC env. I must have lost an hour or more yesterday before realising this.
I’ve recreated something similar in these screenshots:
The following code is perfectly valid in Replit or VS Code, but just gives the useless obtuse error message in FCC

    new_start_mins = (int(start_mins) + int(dur_mins))
    if (new_start_mins >= 60):
        new_start_mins -= 60
        new_start_hr += 1
    print("actual new start hr: " + str(new_start_hr))

Now look again when highlighted:
Rogue tab alert!

Coming from a background of C-style languages it just baffles me that whitespace can cause a syntax error. But tbf, this isn’t the python indentation thing. It’s fine in Replit where you can mix and match tabs and spaces; this is specifically a problem in FCC’s env.

I’d prefer to stay coding in FCC as I like the live preview and also like to continuously run tests, but all of the above (and the lack of autocomplete) make it painful.

This is only temporary, since the platform is still in development (the course is in beta) and error messages will be available soon (at least in the browser console). Running Python in the browser is not an easy task. Therefore, some limitations are expected.

About the lack of autocomplete, to my knowledge, this is intentional: during the learning process is important to think precisely to what you should write to make your code work without relying on additional feature (it’s a pain, of course).

Ah, I misunderstood, sorry. I thought the ‘beta’ was for the specific program (‘scientific programming with python’), not the actual environment.

I was thinking the same about why the autocomplete was missing, and can’t argue, but I do think FCC ought to fix the problem with white space I mentioned (maybe, for now, make the full stops/periods a contrasting color so it’s more obvious?).

The live preview thing is really cool though, don’t think I’ve seen it elsewhere. Keep up the good work, FCC!

1 Like

If I understood correctly, you are referring to the issue with the tab character raising an indentation error. To my experience, this does not happen if you directly type in the editor. The tab characters are automatically converted into spaces. Have you you copied and pasted your code from replit or another code editor, right?

Yes, I thought I’d mentioned already I’d worked between FCC and Replit? It’s necessary to have code in FCC to run tests.

I’ve recently found ‘boilerplate’ versions of the code on replit, but I can’t know for sure that nothing has changed in the beta versions of the projects in FCC. So I’ve mainly been sticking with FCC, but occasionally copy-pasting between it and my own replit page where FCC has been unhelpful i.e. no error messages.

Replit has tabs by default, so that was probably how tabs came to be in FCC. If you somehow manage to mix tabs and spaces in Replit it gives:
TabError: inconsistent use of tabs and spaces in indentation

But when mixing in FCC, the live preview dies, and running tests just gives:
Your code raised an error before any tests could run. Please fix it and try again

I think the typical user would assume there was an error in the code itself, as this is the same behaviour as a syntax error gives. It’s certainly what lost me and hour or 2.

I’m not able to replicate this currently, please let me know if I’m doing it correctly?

  1. Starting with a blank project.
  2. Going to your replit, select all and copy,
  3. Paste into FCC
  4. Seems to output correctly, no errors

The first time I tried this it didn’t seem to work, but each subsequent test has been ok.

By default Replit uses tabs, and FCC spaces. If you were to select all from Replit when set as default tabs, then paste into FCC it would be fine as it’s consistently tabs.

Instead, try copying a single method from a tabbed Replit into a spaced FCC env. Now its mixed and will fail with a generic error message for each test.

It would be great if FCC could elevate such errors, or at the very least, as I suggested earlier, alter the theme so tabs/spaces are shown (as happens when you select text in FCC)

Ah, ok, so it’s the mix.

So, in the meantime, you can just select the entire code and copy/paste it, correct? You’ll only get an error if you copy a portion into existing code edited in the fCC editor?

@shapeshifter42 I’ve found something else for you.

I broke the indentation as described above:

Screenshot 2024-04-01 220908

Then you can right-click or press F1 for the command palette and select “Convert all indentation to tabs” (or spaces) and it will fix all of the code in the editor to match.

Screenshot 2024-04-01 220832

OMG! There’s a command palette? Who knew? :rofl:

Code folding too! I wish I’d known that was there. I was clicking in the gutter but assumed there was no such thing.

Ok, it’s great that I can can change to all tabs/spaces with 1 click, but you would have to know/suspect there was an issue in the first place, and for 2 hours the other day, I didn’t. I have to keep coming back to the issue of the lack of genuine errors being shown or white-space being highlighted.

Thanks for investigating.

1 Like

I was surprised as well! Very happy with that find.

1 Like