Python Data Manipulation
This week, I dove deeper into Python programming, focusing on control structures like loops and conditional statements. These tools are the backbone of data manipulation, helping automate tasks and make decisions in code. I had a mix of excitement and frustration as I worked through the examples in Data Toolkit: Python + Hands-On Math by Todd Kelsey. Loops were straightforward enough—especially for
loops, which repeat tasks a set number of times. However, while
loops required more attention since they run indefinitely unless given a clear stopping condition. I quickly learned that missing a condition could lead to an infinite loop, freezing my Google Colab notebook! Below is an example of a while
loop:
Conditional statements (if
and if-else
) were another essential concept. These statements allow programs to react differently based on specific conditions. I experimented with a simple program that checks if a number is even or odd. The logic seemed simple: if a number is divisible by 2, it's even; otherwise, it's odd. But when I tested my code, I forgot to include an else
statement, and nothing printed when an odd number was entered. Debugging that small mistake helped reinforce the importance of proper indentation and logical structure in Python.
Comments
Post a Comment