Episode 4: Writing Your First Python Code


Welcome back to The Medical Coder’s Path!
If you have been following along, you should now have your Python environment ready, whether you are using VS Code, Anaconda, Google Colab, or even your phone.
Now it’s time for the exciting part: writing your very first Python code! 🎉
🧠 What Will You Learn in This Episode?
How to run your first Python command
How to use the
print()
functionHow Python reads and executes code
How to declare a variable and inspect its value
How to write comments
Two simple examples: one related to healthcare and one from daily life.
Let’s keep it simple and fun. No prior coding knowledge needed!
🛠️ How to Open a New Python File
🟢 On Anaconda (Jupyter Notebook)
Open Anaconda Navigator from your Start Menu or Applications folder.
Click Launch under the Jupyter Notebook section.
A browser tab will open (usually at
http://localhost:8888
).Navigate to the folder where you want to create your file.
Click New > Python 3 (ipykernel) from the top right corner.
A new notebook will open, now you can type Python code in the gray "cells" and click Run.
Try to write the following code:
print("Hello, future coder!")
After that, run the code using the ▶️ “Run” button above
You will see the output below the cell.
📌 Note: Jupyter Notebook saves files with a
.ipynb
extension (Notebook format).
A
.ipynb
file is a Jupyter Notebook file. It stands for "Interactive Python Notebook."
It allows you to write Python code in small sections (cells), add text, images, and explanations, run code, see the results immediately below the code cell, and save everything in one file.
🔵 On Visual Studio Code (VS Code)
Open Visual Studio Code.
Create a new folder or open an existing folder where you want to save your Python file.
After opening your folder, you will see its name. To the right, there are four symbols. Click on "New File".
Enter a name for your file and add the
.py
extension at the end. (e.g.,episode4.py
):In the file, start writing your Python code.
Try to write the following code:
print("Hello, future coder!")
After that, run the code using the ▶️ “Run” button above in the right corner
You will see the terminal open in the lower half of the code editor, displaying the folder and file names, along with the output.
What just happened?
You told Python to display the message inside the quotation marks ““ using the print()
function. It’s the most basic and useful command for beginners.
What is the print()
Function in Python?
The print()
Function is a built-in function that outputs the specified message to the screen (standard output). It is one of the most basic and commonly used functions in Python. It tells Python to display a message or the result of a calculation on the screen.
What Is a Built-in Function in Python?
🧠 In simple terms: print()
is how Python talks back to you.
Whenever you want Python to show something, like text, numbers, or results, you use print()
.
You can also print numbers, variables, or even results of math operations:
print(5 + 3) #Try it in your code editor!
How Python Reads and Executes Code
When you write a Python program, Python reads your code from top to bottom, one line at a time, and executes each instruction step by step.
Think of Python like a person reading a recipe:
It starts at the top.
It reads the first instruction (line of code).
It follows the instructions and does what you told it to do.
Then it moves to the next line.
🧪 Example:
print("Step 1: Starting...")
print("Step 2: Doing something")
print("Step 3: Done!")
🖥️ Output:
Step 1: Starting...
Step 2: Doing something
Step 3: Done!
Python reads and runs the lines in order; it does not skip around unless you tell it to (like with conditions or loops, which we’ll learn later).
📌 Why This Is Important:
Understanding how Python processes your code step by step helps you:
Read and understand other people’s code
Write better programs yourself
Debug problems when something goes wrong
How to Declare a Variable and Check Its Value?
A variable is like a container that stores a value (like a number, a word, or any data). You give it a name, and Python remembers the value for you.
To declare (create) a variable:
age = 25
name = "Ahmed"
age
stores the number 25name
stores the word “Ahmed”
To inspect (see) the value of a variable:
You can use print()
:
print(age)
print(name)
🖥️ Output:
25
Ahmed
💬 How to Write Comments in Python
Comments are notes you write in your code to explain what you are doing.
Python ignores them when running the code; they are just for you (or others) to understand better.
✍️ Single-line comment:
Comments in Python start with #
. When comments start on a new line, they are called block comments, while comments that appear on the same line as code are called inline comments.
# This is a block comment
age = 30 # This stores the person's age/ inline comment
📌Why comments matter:
They help you and others understand your code, especially as projects grow in length and complexity.
Real-Life Examples
Let's look at two examples to see how Python can help us solve simple problems.
🩺 Example 1: Medical Scenario – Checking patient information
# Storing patient information
patient_name = "Mariam"
patient_age = 45
# Printing the information
print("Patient Name:", patient_name)
print("Patient Age:", patient_age)
🖥️ Output:
Patient Name: Mariam
Patient Age: 45
📌What this shows: How to store and print data, which is useful for building medical record systems later.
🏡 Example 2: Daily To-Do List
# Storing tasks for the day
task1 = "Check emails"
task2 = "Attend Python class"
task3 = "Go for a walk"
# Printing the to-do list
print("Today's Tasks:")
print(task1)
print(task2)
print(task3)
🖥️ Output:
Today's Tasks:
Check emails
Attend Python class
Go for a walk
📌What this shows: How Python can help organize everyday routines by storing and displaying tasks.
🧪 Exercise: Create a Simple Patient Profile Program
🩺 Scenario:
You’re working at a health center, and you need to quickly print out a patient’s basic information to share with a nurse. You will store and display the patient’s details using Python.
🎯 What to do:
Create variables to store the following:
Patient's full name
Age
Gender
Department (e.g., Pediatrics, Cardiology, etc.)
Hospital name
Use the
print()
function to display all the information clearly.Add comments to explain what each part of the code is doing.
📝 Example Output:
Patient Information
--------------------
Name: Amina Yusuf
Age: 29
Gender: Female
Department: Dermatology
Hospital: Sunrise Medical Center
💡 Bonus Tip (Optional):
You can also add a short welcome message at the top using print()
— like:
print("Welcome to Sunrise Medical Center")
📩 After you finish, please send a screenshot of your exercise to this email: saja@sajamedtech.com
🚀What’s Coming in Episode 5?
In the next episode, we will explore variables and data types.
💬 Let me know in the comments or messages:
- What setup did you use to run your first code?
- What do you want to build with Python?
Don’t forget to subscribe to Hashnode to get a notification when the next episode is released.
See you tomorrow!
Subscribe to my newsletter
Read articles from Saja Ahmed directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
