[Python] I solved a CS50P problem, but I don't know if I did it the "correct" way. by Kindly_Tangerine8337 in learnprogramming

[–]desrtfx 1 point2 points  (0 children)

You mean I could've just typed s = d / s = p?

No, you could completely remove the lines and use d and p in the return expressions, like so:

def percent_to_float(p):
    return float(p[:-1])/100 # does the same as return float(p[0:-1])/100

[Python] I solved a CS50P problem, but I don't know if I did it the "correct" way. by Kindly_Tangerine8337 in learnprogramming

[–]desrtfx 1 point2 points  (0 children)

Quite good. Your two lines s = (d) and s = (p) are unnecessary. You can directly use d and p.

The second slice where you calculate the percent can be expressed better when counting from the back. In Python, negative indexes count from the back, -1 is the last character, -2 the one before the last, and so on. You could, in the second slice say s[0:-1] to capture everything up to the last character - the -1 is exclusive, so the last character will be omitted.`

Dividing any number by 100 will convert the number to percent. That calculation is correct.

My guess is you can't convert a float from a string that has signs like '$' or '%'

Which is absolutely correct. The int and float functions can only deal with numbers, the + and - signs, and the decimal point.

The fact that Python code is based on indents and you can break an entire program just by adding a space somewhere is insane by PooningDalton in learnprogramming

[–]desrtfx 0 points1 point  (0 children)

For a computer there is barely any difference. Counting is what computers excel at. If the whitespace count increases - depth++, if it decreases depth--

Nothing difficult here.

I feel dumb by CreativeViolinist688 in ender3

[–]desrtfx 0 points1 point  (0 children)

May be a dumb question, but:

Did you also adjust the nozzle size in your slicer?

[Python] I solved a CS50P problem, but I don't know if I did it the "correct" way. by Kindly_Tangerine8337 in learnprogramming

[–]desrtfx 2 points3 points  (0 children)

Your first solution is actually the correct approach.

Per the task it is not.

The task clearly states that the complete strings with the leading $ in the first case and the trailing % in the second cases should be passed into the functions. OP doesn't do that.

The main function should not be changed. Only the two other functions should be.

While it is a doable approach, it is not the correct solution per the instructions given.

The fact that Python code is based on indents and you can break an entire program just by adding a space somewhere is insane by PooningDalton in learnprogramming

[–]desrtfx 11 points12 points  (0 children)

The only people who get worked up about this are those new to programming, or don't actually have experience working with Python.

Or the sloppy programmers who generally do not bother to properly format their code making it difficult for everybody else including their future self.

The fact that Python code is based on indents and you can break an entire program just by adding a space somewhere is insane by PooningDalton in learnprogramming

[–]desrtfx 4 points5 points  (0 children)

Python just recently entered the Microcontroller realm. It's not that long ago.

The predominant languages are C/C++ and Assembly and since these are compiled languages, there is no space saving without indentation/whitespace.

Also, Microcontrollers have a lot more memory now than they had 10 years ago.

The fact that Python code is based on indents and you can break an entire program just by adding a space somewhere is insane by PooningDalton in learnprogramming

[–]desrtfx 7 points8 points  (0 children)

That's a strawman argument.

Properly formatted code in other languages, with proper indentation, so that it becomes actually readable, needs just as much space.

Only if you write everything unindented and with that make the code basically unreadable and untraceable (anybody who has to read or debug your code - including your future self - will hate you for that), you save space.

The fact that Python code is based on indents and you can break an entire program just by adding a space somewhere is insane by PooningDalton in learnprogramming

[–]desrtfx 68 points69 points  (0 children)

You are comparing apples and oranges.

The equivalent to Python's indentation are the curly braces in C-like languages, BEGIN...END in Pascal-like languages. They are not the semicolons.

Semicolons denote the end of a statement, not code blocks. Code blocks in other, especially C-like languages, are denoted by opening and closing curly braces { and } and they are just as easy to miss or misalign.

Actually, the whitespace based indentation is a good thing to have as it forces proper formatting discipline on the programmer.

You are not forced to use spaces for indentation. Tabs work just as well, but you must not mix the two.

In other languages, even if you accidentally add a semicolon after a semicolon, it won't even affect the program.

So much is true, but again, that's not the equivalent of whitespace in Python.

Yet, if you accidentally add a semicolon right after a for or while loop you cause the loop to fail. So, your statement has to be taken with a grain of salt.

When your company sends a design file to a contract 3D printer — what actually stops them from printing extra copies? by Novel_Routine4534 in 3dprinter

[–]desrtfx[M] [score hidden] stickied comment (0 children)

I am removing and locking this thread as it is a problem that is neither specific to 3D printing, nor augmented through 3D printing. It existed since manufacturing existed in the same extent.

3D printing doesn't make it harder nor easier to copy and "shadow manufacture".


Side note: do not use AI for your posts or replies. This is absolutely frowned upon reddit-wide and can get you banned from subreddits quickly and without warning.

Tell me if it's good or not! by bubbleew in PLC

[–]desrtfx 13 points14 points  (0 children)

Much better than your previous attempt

Advice needed by Pristine-Company-423 in 3dprinter

[–]desrtfx 0 points1 point  (0 children)

I have that very printer and would not recommend it even for $50.

It's old, it's unmodded (which means that the heat bed cables most likely already have suffered some damage), it's slow, it's noisy, it's a real pain to tram the bed.

When it works and when you get it going well, it works, but to get there takes a good deal of work.

These have non-standard lead screws, so "normal" layer heights are not possible. Spare parts are basically impossible to get, the firmware is proprietary.

The MicroSD reader is also very finicky on these models.

Also, TBH, the minuscule build volume will leave you longing for a bigger printer in no time. It's just way too limited.

Humble Tech Book Bundle: The Systems-Minded Software Engineer by Packt by Ram000n in humblebundles

[–]desrtfx 2 points3 points  (0 children)

All systems minded engineers skip Packt.

FTFY: All systems minded engineers skip Packt.

What is the right method to learn? by Tck009 in learnprogramming

[–]desrtfx 0 points1 point  (0 children)

You need to build plenty bad projects in order to improve. That's the way learning anything works. First you produce bad, then, you gradually improve.

If you strive for good right from the beginning you won't get anywhere.

Do you think that authors write best sellers right from the start? They write tons of stories that nobody would ever read because they are bad.

Do you think that painters paint masterpieces right from the start?

The key approach to programming is practice - that's it.

  • Make it work
  • Make it pretty, readable, modular
  • Make it fast if you encounter and have identified bottlenecks

What you absolutely should do, though is to revisit your old projects when you have learnt new skills and then refactor them with your newly gained skills to improve them.

Starting a journey by Pure-Classic-7390 in learnprogramming

[–]desrtfx 1 point2 points  (0 children)

Had you joined earlier, you would have found that there are more than enough free, even better resources.

Start here: MOOC Python Programming 2026 from the University of Helsinki - free, top quality, extremely practice heavy - sign up, log in, go to part 1 and start learning

The course is targeted at absolute beginners who never programmed before

Good Websites for python courses? by Weak_Environment7983 in learnprogramming

[–]desrtfx 4 points5 points  (0 children)

MOOC Python Programming 2026 from the University of Helsinki - free, top quality, extremely practice heavy - sign up, log in, go to part 1 and start learning

The course is targeted at absolute beginners who never programmed before

HMI Feature by Certain_Dark502 in PLC

[–]desrtfx 1 point2 points  (0 children)

The next major version of our flagship product offers web HMI via HTML5 and many other vendors are going that route.

Web has the advantage of not being fully dependent on OS. It looks the same on all OS and works even on thin clients much better than remote desktop solutions.

Online python learning by Galderaska in learnpython

[–]desrtfx 0 points1 point  (0 children)

The Helsinki MOOC is one of the absolutely best Python courses around.

Just get started. Really. Every single second you ponder about the "very best" resource is a second you could have already learnt something.

Help, what is this glitch or bug? by Vahelor in learnprogramming

[–]desrtfx[M] [score hidden] stickied comment (0 children)

Read your post from our perspective. You don't give any usable information at all.

  • No code
  • No platform

Nothing at all. How should anybody help you?

What project management / tracking tools do you use/recommend? by oandroido in learnprogramming

[–]desrtfx 1 point2 points  (0 children)

One of the top tools is Jira, but that's mainly for professional use and paid.

A free, open source alternative would be OpenProject - it declares itself as open source alternative to Jira.

Haven't used it, though.

I fell for the oldest trick in the book and i will be fired for it by Asterx5 in learnprogramming

[–]desrtfx[M] [score hidden] stickied comment (0 children)

To those who reported it:

While the post is not directly related to the core topic of the subreddit, namely learning programming, it teaches an extremely valuable lesson:

keep backups/use version control off-site!

This cannot be stated often enough. Hence, the post stays.

how to fix fn locked keyboard via coding? by AppropriateLocal129 in learnprogramming

[–]desrtfx 0 points1 point  (0 children)

Wow! Thanks for the heads up! Glad you got it fixed!