Is it worth doing exercises that teach not very optimized ways of doing a program?

Asked

Viewed 58 times

0

Well, I’m learning python and sometimes I come across some relatively difficult exercises, for example, an exercise where the program had to read a value in money and say in how many notes of 1, 5, 10, 20, 50, 100 that money could be represented.

The problem is that only conditional structures and mathematical operators could be used.

Doubt

It is worth doing this kind of exercise and learning how to make a code that could be simplified ?

What is the purpose of this type of exercise ?

  • 1

    Test your logical thinking. Making code that gives the expected result is not necessarily making good code. The ideal is to solve the same exercise in the most diverse ways that can and compare them, understand the differences and the main characteristics of each.

1 answer

1


In fact, if you already understand what the code would look like, and you can imagine it in your mind, you don’t have to. In particular, if you can’t use loop structures, I recommend not to do it - too artificial, and too useless (you won’t be able to solve it in a generic way, for any value). Instead, take more challenging exercises

The goal is just to make sure that those who are learning to program for the first time understand well conditionals - if you have already understood, there is no reason to follow these restrictions: any real problem you catch will exercise the use of conditionals too.

A place that has some legal problems is project Euler - all problems are numerical in nature, and the answer is a single number, but almost all require you to create a program to get to the answer - and it doesn’t matter to them how you did the program or in what language, just the answer number. The exercises get gradually more difficult, and soon it becomes natural that either you make the algorithm more efficient, or your program would run a couple of years running.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.