Week 3: Getting More Comfortable with Python
This week of my Python learning journey focused on some of the things that make Python more practical beyond writing basic programs. I worked with modules, JSON, dates, error handling, user input, pip, and virtual environments.
At first, some of these concepts looked straightforward, but working through the assignments helped me understand why they are important when building actual Python applications.
Working with Python Modules
One of the first things I explored was the difference between a module and a package.
A module is essentially a single Python file containing code such as functions, classes, or variables, while a package is a collection of related modules organised in a folder.
I also practised importing modules in different ways:
and:
This helped me understand the difference between importing an entire module and importing a specific function from it.
I also worked with the datetime and json modules, which became some of the more practical parts of the week's work.
Working with JSON
I learned how to convert Python objects to JSON and JSON back to Python objects.
For example:
I also worked on a larger exercise where I stored a list of student file records in a JSON file and then read the file back into Python.
This was particularly useful because it showed me that JSON isn’t just something to learn theoretically. It can also store and retrieve structured data.
I also learned what happens when you load invalid JSON. Python raises a JSONDecodeError, which reinforced the importance of handling errors properly.
Dates and Time
I spent some time working with Python’s datetime module.
I practiced:
- Getting the current date and time
- Extracting the year, month, and day
- Formatting dates using strftime()
- Converting strings into dates using strptime()
- Calculating the number of days between dates
One distinction that became clearer to me was:
strftime() is used to convert a date into a formatted string, while strptime() is used to convert a string into a datetime object.
I also built a small date calculator that takes a person’s birthday and calculates how many days are left until their next birthday.
Try/Except and Error Handling
Another important part of this week’s learning was error handling.
Instead of allowing a program to crash whenever a user enters something unexpected, I learned how to use try and except to handle errors.
For example:
This helped me understand that errors aren’t necessarily something to avoid completely. They are also something a program should be prepared to handle properly.
I also practiced using while True with try/except to keep asking for valid input until the user provides an integer.
The while True part initially made me wonder why the loop needed to continue indefinitely. I eventually understood that the break is what stops the loop once valid input is provided.
Building a Math Quiz
One of my assignments was to build a small Math Quiz.
Get Righteous Ifada’s stories in your inbox
Join Medium for free to get updates from this writer.
The program generates five random questions involving:
- Addition
- Subtraction
- Multiplication
- Division
It then keeps track of the user’s score.
This exercise brought together several concepts I had learned, including:
- random
- if/elif/else
- for loops
- try/except
- User input
- Variables and calculations
It was a simple project, but I found it useful because I wasn’t just writing isolated pieces of code anymore. I was combining different concepts to make one working program.
Pip and Virtual Environments
I also learned more about pip and virtual environments.
pip is Python's package manager and allows us to install external packages.
For example:
pip install requests
I also learned why virtual environments are useful. Instead of installing every package globally, a project can have its own isolated environment and dependencies.
I created a virtual environment and installed packages such as requests and numpy inside it.
The idea of having different environments for different projects made more sense once I actually worked with one.
What I Found Challenging
The most challenging part of this week’s work was not necessarily writing the individual lines of code. It was understanding how the different concepts fit together.
For example, the date calculator required me to think about:
- Getting user input
- Converting the input into a datetime object
- Comparing dates
- Calculating differences
- Handling invalid dates
The JSON file assignment was another good exercise because it required me to move between Python objects, JSON strings, and actual files.
These exercises helped me realise that programming is often less about memorising syntax and more about understanding what needs to happen and which tools can help me achieve it.
What I Learned This Week
By the end of Week 3, I had a better understanding of:
- Python modules and packages
- Importing functions and modules
- JSON serialization and deserialization
- Reading and writing JSON files
- Working with dates and times
- Exception handling
- User input validation
- pip and Python packages
- Virtual environments
- Combining different Python concepts into small projects
I’m still learning, and I definitely need more practice, especially when several concepts have to work together. But compared to where I started, I’m becoming more comfortable reading Python code, understanding errors, and figuring out how to approach a problem.
Week 3 was less about learning individual Python commands and more about understanding how those commands can work together to build something useful.







