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.
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.
– Woss