Codéx
Codex is a coding platform included in my GitHub Dev Pack through the GitHub Global Campus membership. It provides a fun and interactive way to learn programming languages by offering quests, games, and hackathons alongside a community of other learners and developers. I'm currently learning Python, with plans to expand my skills to SQL and JavaScript.
Project 1: Temperature
Video Walk-Through
Durration 2:29
Project 2: Coin Flip
Video Walk-Through
Durration 2:03
Project 3: Magic 8 Ball
My Code
Video Walk-Through
Durration 5:16
C.A.R Method - Project Breakdown
Challenge
I was tasked with creating a Magic 8 Ball program that responds to Yes or No questions with one of nine possible random answers. The challenge involved using the .randint()
function from the random
module to generate a random number, which would then correspond to a specific response. My goal was to correctly structure the code to achieve this random selection while ensuring that the user's question and the Magic 8 Ball's answer were displayed correctly
Action
I began by constructing my code using my existing knowledge, referring back to previous projects and units to guide my approach. Initially, I declared a variable to store the randomly generated value and set up the conditions to map each number to a corresponding Magic 8 Ball response. Confident in my code, I ran it, expecting to see both the question and a random response. However, the only output was the question itself, without any Magic 8 Ball response.
I spent the next two hours debugging, rewriting sections of the code, and reviewing old course materials to identify the issue. Eventually, I decided to ask Google's Gemini to analyze my code, thinking that perhaps I had overlooked something simple. Upon analysis, Gemini pointed out that I had made a common beginner's mistake: the hierarchy of my code was incorrect. Specifically, I had placed the input question too early in the code (within the first few lines), which caused the program to process the question before the random selection of the Magic 8 Ball response. To resolve this, I moved the question input to line 23, ensuring the program could sequentially execute the random number generation and corresponding response before handling the question.
Result
After adjusting the code structure by placing the input question at the end, the program executed correctly. The Magic 8 Ball now provides a random response from the list of nine possible answers, alongside the user's question. This experience reinforced the importance of proper code structure and sequencing, and it highlighted the value of seeking external help when stuck on a problem.