Anirudha
← Work
15 Days of CodingDay 12September 23, 2025~3 min read

Namescapes, Scope, Number Guessing Game

First solution that you think doesn’t have to be the final solution

After finishing the Blackjack game and gambling away virtual money yesterday, I was in high spirits and itching to code again. But work comes first. With summer vacation ending for many colleagues, today was packed with meetings and some deep product work.

Once I wrapped that up, I dove into Python and learned about Namespaces and Scope. Variables can live in the global scope (the main code) or the local scope (inside a function). A variable defined inside a function is local to that function and won’t affect a global variable with the same name. If you do want to modify a global variable inside a function, you need to explicitly declare it with the “global” keyword.

Block scope doesn’t really exist in Python the way it does in some other languages (like C++ or Java). For example, a variable inside an if-statement is still accessible outside of it. Slightly weird at first, but you get used to it once you use it enough and unpopular opinion: I like this feature.

Guess what? No really, that’s the game I built today, a Number Guessing Game in Python. The computer picks a number between 1 and 100, and the player has to guess it in a limited number of tries. Pretty straightforward on the surface, but I ended up learning a surprising amount while building it.

I started by trying to create a number list with a for loop and .append() which was me overcomplicating things. But then I discovered .extend(range()), which made the whole thing way cleaner and simpler. The computer then randomly picks one number from this list as its secret number using the ‘random’ library.

The game has two difficulty levels: Easy with 10 chances to guess the correct number and Hard with 5 chances to guess the correct number. My first thought was of writing a function for each round and repeating it “x” times depending on the difficulty. But after sketching it out, I realized it would quickly become messy. So instead, I rewrote my logic and created two separate functions, easy_round() and hard_round(). Both use while loops that keep asking the user for guesses until either they win or they run out of tries (*update: combined both these functions into a single function to make the code even shorter). If the guess is high or low, the game gives a hint. And if the user loses, the game reveals the computer’s secret number.

The biggest insight for me today was you don’t have to stick to your first idea and try to get it to work. Your first approach does not have to be your final approach. I had to change my approach a couple of times once I realized how complicated it was becoming. And that is okay, that is normal. That is exactly what coding is. You try, you break things, you realize it won’t work, you rethink and then you try something else until you find the best way forward.

Now, I am off to Ikea. The missus wants a few things from there and I love tagging along, mostly to fantasize about the fancy furniture we definitely can’t afford right now. Until tomorrow!