Section One: Building the Foundation — From My First Line of Code to Working with Data
_
1. The beginning: Taking my first steps into Python
_
Every programmer has a starting point. Some begin with complex applications, while others begin with a single line of code that displays a message on the screen. My journey into Python began with the basics, starting with the famous programming tradition of printing “Hello World.”
At first, the objective was simple: understand how to write a command, run it, and see the result. However, learning Python was not just about memorising commands. It was about understanding how a computer interprets instructions and how I could use those instructions to solve practical problems.
My first program looked like this:
`
python
print("Hello World")
`
The print() function tells Python to display information on the screen. The words "Hello World" are enclosed in quotation marks because they are text, which Python calls a string.
Although this program is simple, it introduced me to several important programming concepts:
- 1. - Syntax: The rules that determine how Python code should be written.
- 2. - Functions: Reusable instructions that perform specific tasks.
- 3. - Strings: Text values enclosed in quotation marks.
- 4. - Execution: Running code to produce an output. This was my first important lesson: programming starts with small instructions, but those instructions can eventually be combined to build powerful systems.
**
2. Learning to give Python instructions
**
After understanding how to display a message, the next step was learning how to store information and work with it.
I discovered variables, which allow me to give data a name so that I can use it later. Rather than writing the same value repeatedly, I can store it once and refer to it whenever needed.
For example:
name = "Kevin"
age = 30
course = "Data Science"
print(name)
print(age)
print(course)
The numbers and personal details above are illustrative; the important lesson is how variables work.
In this example, name, age, and course are variables. Python associates each variable with a value, allowing the program to retrieve and use that value.
I also began understanding that Python handles different kinds of data differently.
name = "Kevin" # String: text
age = 30 # Integer: whole number
height = 1.75 # Float: decimal number
is_learning = True # Boolean: True or False
print(type(name))
print(type(age))
print(type(height))
print(type(is_learning))
The type() function helps identify the type of data stored in a variable.
This became important as I progressed towards data analysis. Data analysts frequently work with names, dates, prices, quantities, customer records, and numerical measurements. Understanding data types is essential because calculations must be performed on appropriate values.
For example, Python cannot always add a number to a string in the way a person might expect. Learning how to distinguish text from numerical values is therefore a foundational skill.
**3. Receiving information from the user**
My learning progressed from displaying information to allowing a program to receive information.
Python uses the input() function to collect information typed by a user.
name = input("Enter your name: ")
print("Welcome to Python,", name)
This makes the program interactive. Instead of displaying the same fixed
message every time, it can respond to the person running it.
However, I also needed to understand an important detail: input() returns text, even when the user types a number.
Consider this example:
age = input("Enter your age: ")
print(age)
print(type(age))
Even if someone enters 25, Python initially treats the result as a string.
To perform mathematical calculations, I can convert the input into an integer using int().
age = int(input("Enter your age: "))
next_year_age = age + 1
print("Your age next year will be:", next_year_age)
This introduced me to type conversion, a concept that becomes especially important when processing data from CSV files, spreadsheets, forms, and databases.
For example, a CSV file might contain "1500" as text when I need the value 1500 to calculate revenue. Knowing when and how to convert data is part of preparing it for analysis.
4. Making decisions with conditional statements
The next stage was teaching Python to make decisions.
Programs become more useful when they can respond differently depending on the information they receive. Python supports this through conditional statements such as if, elif, and else.
For example:
sales = 15000
if sales >= 10000:
print("Target achieved")
else:
print("Target not achieved")
The program checks whether sales are at least 10,000. If the condition is true, it prints one message; otherwise, it prints another.
I can extend this logic:
sales = float(input("Enter total sales: "))
if sales >= 20000:
print("Excellent performance")
elif sales >= 10000:
print("Target achieved")
else:
print("More sales effort is required")
This example connects programming to practical business operations. A sales analyst might use similar logic to classify sales performance, identify low-performing products, or flag transactions that require attention.
I was learning not only how to write Python, but also how to translate everyday business rules into instructions that a computer can execute.
**
5. Repeating tasks with loops
**
Another major step was learning how to make Python repeat instructions without writing the same code over and over.
Python has two common loop structures: for loops and while loops.
A for loop is useful when I want to process items in a collection or repeat an operation a known number of times.
for number in range(1, 6):
print(number)
This prints the numbers 1 through 5. The ending value in range() is excluded.
A while loop repeats as long as its condition remains true.
count = 1
while count <= 5:
print(count)
count += 1
The statement count += 1 increases the counter by one each time the loop runs. Without an appropriate stopping condition or counter update, a while loop could continue indefinitely.
These concepts helped me understand how Python can automate repetitive work. Rather than processing each record individually, a program can loop through hundreds or thousands of records and perform the same operation consistently.
In data analysis, this principle is useful for checking records, applying rules, generating summaries, and processing multiple files.
- Organising information with lists and dictionaries As the programs became more involved, I needed better ways to organise data. A list stores multiple items in a single collection.
products = ["Ufuta", "Kimbo", "Cowboy", "Chipsy"]
print(products[0])
print(products[1])
Python uses zero-based indexing, meaning the first item has index 0.
Lists can also be modified:
products.append("Bahari")
products.remove("Kimbo")
print(products)
This introduced me to adding, removing, retrieving, and organising collections of information.
A dictionary, on the other hand, stores information as key-value pairs.
product = {
"name": "Ufuta",
"category": "Cooking oil",
"price": 250
}
print(product["name"])
print(product["price"])
A dictionary is useful when the values describe different attributes of the same object.
For example, a product record might have a name, category, price, and stock quantity. A customer record might contain a name, telephone number, and location.
Lists and dictionaries are important building blocks because they prepare me to work with more structured collections of records and, eventually, tabular data.
7. Creating functions and reusable code
As I learned more, I began to see why writing all instructions in one long block of code was not always a good approach.
Functions allow me to group instructions under a name and reuse them whenever required.
def calculate_total(price, quantity):
total = price * quantity
return total
result = calculate_total(250, 4)
print("Total:", result)
Here, calculate_total() receives a price and a quantity, multiplies them, and returns the result.
The keyword def defines a function, while return sends a result back to the part of the program that called the function.
Functions help make code easier to read, test, debug, and maintain.
For instance, if I were building a sales-analysis program, I could create separate functions to calculate revenue, apply discounts, classify performance, and summarise orders.
Instead of rewriting each calculation repeatedly, I could call the appropriate function whenever I needed it.
This was another significant step in moving from writing isolated lines of code towards developing organised programs.
8. Understanding errors and learning how to debug
One of the most important parts of my journey has been learning that programming does not always work perfectly on the first attempt.
I encountered errors such as undefined variables, missing imports, and problems running code in my development environment. These challenges taught me that successful programming involves more than knowing Python syntax. It also requires the ability to identify problems, understand error messages, and find the correct solution.
For example, I encountered the problem of np not being defined when working with NumPy.
import numpy as np
numbers = np.array([10, 20, 30, 40])
print(numbers)
The first line imports NumPy and gives it the familiar abbreviation np.
Without that import, Python does not know what np refers to.
Similarly, if I try to use a variable before defining it, Python raises an error.
# Incorrect: the variable has not been defined.
print(total_sales)
# Correct:
total_sales = 15000
print(total_sales)
I learned to pay attention to the difference between syntax errors, name errors, type errors, and problems caused by the environment in which code runs.
This distinction matters because not every problem requires changing the code. Sometimes the code is correct, but the selected Python interpreter or notebook kernel is not configured properly.
9. Moving from simple scripts to Visual Studio Code
As my ambitions grew, I began using Visual Studio Code (VS Code) as my programming environment. This allowed me to work with Python files, notebooks, CSV datasets, and project folders in one place.
I also had to understand the relationship between Python itself and the tools used to run it.
Python is the programming language. VS Code is the editor. A Python interpreter executes Python code, while a Jupyter kernel allows Python code to run interactively inside a notebook.
During my setup process, I encountered problems involving multiple Python installations and kernels, including Python 3.10, Python 3.12, and Python 3.13. I initially tried several fixes, including installing ipykernel, but the errors continued.
Eventually, I resolved the environment issue and established a working virtual environment at:
C:\Users\Administrator.venv\Scripts\python.exe
A virtual environment keeps the packages for a project separate from other Python installations. This helps reduce conflicts and makes it easier to reproduce the environment in which a project runs.
I also learned that a notebook can contain code that was working moments earlier, yet fail after the kernel changes or restarts if required variables and imports have not been recreated.
The lesson was important: learning to code also means learning how to manage the tools that execute the code.
I now have practical experience troubleshooting my development environment rather than treating every error as a programming mistake.

Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.