By Hillary Nartey | AI Data Specialist in Training
Welcome Back!
This is Day 2 of my Python learning journey. If you missed Day 1, I shared how I got started, the free tools I am using, and why I chose Python as my first programming language.
Today I covered three important Python basics:
- Variables
- Data Types
- Conditionals (if, elif, else)
And the best part? I built a small real-world project to practice everything together!
Variables
A variable is simply a container that stores a value. Think of it like a labeled box where you keep information.
name = "Hillary"
age = 25
price = 9.99
Each of these is a variable. name stores text, age stores a whole number, and price stores a decimal number.
Data Types
In Python, every value has a data type. Here are the basic ones I learned today:
| Data Type | Example | Description |
|---|---|---|
int |
25 |
Whole numbers |
float |
9.99 |
Decimal numbers |
str |
"Hillary" |
Text (string) |
bool |
True / False |
Yes or No values |
You can also tell Python exactly what type a variable should be. For example:
amount: int = int(input("Enter your shopping amount: "))
Here I am telling Python that amount should be an integer, and I am converting the user's input into one using int().
Conditionals (if, elif, else)
Conditionals let your program make decisions. It checks a condition and runs different code depending on whether it is TRUE or FALSE.
The basic structure looks like this:
if condition:
# do this
elif another_condition:
# do this instead
else:
# do this if nothing above is true
My Mini Project: Shopping Discount Calculator 🛒
To practice everything I learned today, I built a simple shopping discount calculator. It takes the amount a customer spends and automatically calculates their discount and final price.
amount: int = int(input("Enter your shopping amount: "))
if amount < 50:
discount = 0
print("No discount")
elif amount >= 50 and amount <= 99:
discount = 0.10
print("You have 10% discount")
elif amount >= 100 and amount <= 199:
discount = 0.20
print("You have 20% discount")
else:
discount = 0.30
print("You have 30% discount")
final = amount * (1 - discount)
if final > 150:
print("You are a big spender")
else:
print("Great deal")
print(f"Your final price is: ${final}")
How it works:
- The user enters how much they are spending
- The program checks which discount range they fall into
- It calculates the final price after the discount
- It also checks if the final amount makes them a "big spender."
For example, if you enter $120:
- You get a 20% discount
- Your final price becomes $96.00
- And you get a "Great deal" message!
What I Learned From This Project
Building this small project taught me more than just reading about variables and conditionals. I learned how to:
- Take user input with
input() - Convert data types using
int() - Use multiple conditions with
elif - Combine conditions using
and. - Calculate values using arithmetic operators
- Display results using f-strings like
f"Your final price is: ${final}".
Key Takeaways from Day 2
- Variables store information that your program can use
- Data types tell Python what kind of information is being stored
- Conditionals allow your program to make decisions
- The best way to learn is to build something — even something small!
What's Coming on Day 3?
Next, I plan to cover:
- Lists — storing multiple values in one variable
- Loops — repeating actions automatically
- Another small project to practice!
Thanks for following along! If you are also a beginner, drop a comment below — let's learn together! 🚀
Written by Hillary Nartey | AI Data Specialist in Training
Top comments (0)