DEV Community

Cover image for Road to Genius - Python Series level 1
Ilya Nevolin
Ilya Nevolin

Posted on

4 1

Road to Genius - Python Series level 1

In this post I will solve and explain several Python code challenges from Codr's Ranked mode. The goal is to reach the Genius level, so join me at Codr!

Instead of posting one challenge per day, I will instead post several in one.

Alt Text

The first code asks us to fix a bug, which should be a number such that the answer R = 30. The answer is pretty simple, the people variable is a list of objects with name and age. The bug is Ana's age, with the if-condition below requires Ana's age, since R should be 30, we know that 30 is her age.

Alt Text


Alt Text

Here we have two bugs, the first one is R's value, and if you look at the code you see that R is being used as a boolean. Since R should eventually be False, then R should be initialized as False, unless the if-condition is true, which it shouldn't as long as the rocket isn't equal to 3.

Alt Text


Alt Text

The same algorithm as before, this time the first bug should be the arr variable. The second bug's value doesn't matter because the if-condition won't execute anyway.

Alt Text


Alt Text

A very simple one right here. We need to fix the operator on the second line, which is highly like to be an assignment =.

Alt Text


Alt Text

A slightly more complicated algorithm here. We need to fix a bug in the function nonzero as well as one of its inputs. The first bug is a variable name which should be j, since it is used below and should be declared.

To fix the red apple, we need to figure out what the algo does. So given an input list of 4 numbers and i=3, it should return 4. Here's some pseudo code of that function:

j = i+1 = 3+1 = 4
while(j < 4 and ...)  --> j is not less than 4, so we can skip the while loop
return j (=4)
Enter fullscreen mode Exit fullscreen mode

The values inside the input array are irrelevant because the while-loop isn't executed, so the red apple can by anything.

Alt Text


As easy as that, we made it to the 2nd "Smart" level. If you enjoyed this post, make sure to join Codr, like and follow <3!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)