FOSS project to learn Python

Let me just shamelessly showcase my pet project here: https://hackinscience.org

It’s a free and open-source (no ads, no trackers, …) collection of Python exercises with automated correction so you can learn or sharpen your skills easily;

I’d happily paste some screenshots but it’s way more interesting to play with it, no account creation is needed, maybe try, I don’t know… this one: HackInScience — Longest word? :slight_smile:

I started this with a bunch of friends like 8 years ago, it don’t have a lot of users but still (I see like 10k successful answers passing the correction bots per month, so it’s not bad).

7 Likes

Options are sign in or sign up. Example page requires sign in to write. (May try later.) Looks like it could be a good thing. Answering simple beginner questions here and on SO does not scale very well.

EDIT: strike out incorrect statement

Strange. When I hit HackInScience — Longest word for example in a private window, I can type code right away and the submit button works. Can you tell me more?

On retry, it works. I crossed out the mis-information. Sorry about that.

At first, I omitted ‘return’ and did not account for empty text. I like the two panel design, which I use routinely editing and testing in IDLE, with side-by-side editor and shell windows. It is a bit nice not having to write the tests, but I don’t like not knowing what tests were run. If you don’t want to show ahead of time, could print names of tests passed in results and then the failure.

Printing anything disables the call of longest word, or at least a report of whether it passed. But I do like being able to test function on known inputs and see result. ‘Word’ is not defined by seems to be any sequence of non-whitespace.

Thanks for the detailed feedback!!

Printing anything disables the call of longest word, or at least a report of whether it passed

This behavior envolved a lot since like a year, you found a partially transitionned exercise (the call happened, the answer were deemed correct, but the congratulation message was not printed). I fixed it:

I don’t like not knowing what tests were run. If you don’t want to show ahead of time, could print names of tests passed in results and then the failure.

I like the idea, also seeing that more tests passes each time one enhance something can be motivating.

1 Like

I did 19 of the exercises. Saw a few typos (reported 1) and ungrammatical phrasings. Using Roberge’s ‘Friendly’ is a great idea.

I thought about how to partly enforce a solution method without ‘reading’ the code and realized much can be done with classes whose instances ‘have’ an object and restricted methods. For instance, to require use of ‘+=’, an instance with an iadd method could be passed as an answer object to be returned. A function wrapper with call could by used for iterative versus recursive solutions. I will try this for a project of mine and maybe submit something.

1 Like

On recognizing prime integers, you might want to catch functions that say -1 is prime.

W.r.t. the change making problem, your checker doesn’t detect implementations of the obvious greedy algorithm, which is not always optimal.

This implementation passed the test for “read a file”:

from pathlib import Path
print(Path("words.txt").read_text())

Please don’t let people forget encoding="utf-8"

It’s unnecessary on many platforms and will be unnecessary on all platforms in a few versions:

Yes, I know that. Until Python 3.14 is obsolete (which is still quite some time ahead), not specifying the encoding is an easy footgun for students, who tend to be overwhelmingly on Windows.

1 Like

I am puzzled. stdlib modules do not have encoding... and the run and import anyway. Jean, where did you think encoding should be? (Windows user.)

In read_text().

If the problem does not specify the encoding of the file, I think it reasonable to assume that it was written in the system default, in which case adding encoding="utf-8" would seem wrong where that is not the system encoding.

The reasoning behind PEP 686 is that UTF-8 is becoming the de facto “go to” encoding, including on Windows systems where the locale encoding is a legacy encoding, which is why the default encoding of open() and Path.read_text() is going to change.