Tag: programming
-
Flash Card Project: Exploring Data Types and Variables in Python
I recently completed a project called the Flash Card Project, which was an exciting learning experience that deepened my understanding of Python’s versatility with data types and variables. This project involved using various Python features like dictionaries, lists, and Pandas to manage data and display flash cards for language learning. Here’s a breakdown of the…
-
Managing JSON Files in Python: A Practical Approach
Working with data in a structured and efficient way is key to building powerful applications. Recently, I’ve been exploring JSON (JavaScript Object Notation) files and how to manage them in Python. I wrote a small project where I handle website credentials like email and password, storing them securely in a JSON file. Let’s dive into…
-
The Importance of Attribute Order in Class Initialization
When writing code for a game called Snake, I encountered an error while trying to run the program. Here’s the error message: Understanding the Error This error occurs because the create_snake method is attempting to use the self.x attribute before it has been initialized. Let’s examine the problematic code: In the above code, self.create_snake() is…
-
Effortlessly Extract and Print Dictionary Items with Units in Python
Extracting and printing specific items from a dictionary in Python could be a nightmare. You may want to print only the values or keys. Maybe you want to print both in one report or what could you do if you are adding additional information such as units? Let’s say you have a dictionary with a…
-
Efficiently Picking Random Elements in Python: randint vs. choice
If you have a list and you want to randomly choose an element from that list you can use, as I did, a complex or easy way. Maybe you have a list with a nested dictionary with a celebrity’s name, number of followers, career, and country of origin. One way to do this is by…
-
Mastering Control Flow: Using While Loops and Conditionals to Meet Specific Conditions
Within the logic of the Blackjack game, there is a condition that must be met. After the user picks his cards, it is time for the computer to play. The computer has to ask for a card when the sum of its deck is less than 16. The original logic was: Input: Output: computer’s final…
-
Efficient List Manipulation in Python: When to Use ‘append’ and ‘extend’
Let’s say I created a function in Python to deal a group of cards. The Ace is represented by 11, Jack, Queen, and King by 10 and the rest of the deck shows its face value. This function will randomly take an element from the list named cards and return a list with a number.…