Introduction
In this tutorial, you'll learn how to create a simple phone comparison tool using Python that helps users evaluate budget smartphones like the iPhone 17e, Google Pixel 10a, and Samsung Galaxy A56. This practical project will teach you fundamental Python concepts while helping you understand how to organize and compare data about different devices. By the end, you'll have a working program that displays smartphone specifications in an easy-to-read format.
Prerequisites
To follow this tutorial, you'll need:
- A computer with Python installed (version 3.6 or higher)
- A text editor or IDE (like VS Code, PyCharm, or even Notepad)
- Basic understanding of what smartphones are and how they differ in features
Step-by-Step Instructions
Step 1: Set Up Your Python Environment
First, make sure Python is installed on your computer. Open your terminal or command prompt and type:
python --version
If you see a version number, you're good to go. If not, download Python from python.org and install it following the instructions for your operating system.
Step 2: Create Your Project Folder
Create a new folder on your computer called phone_comparison. This will be your project directory where you'll store all your files. Open this folder in your text editor.
Step 3: Create Your Main Python File
Create a new file named phone_comparison.py in your project folder. This will be the main file that runs your comparison tool.
Step 4: Define Your Smartphone Data Structure
Start by adding this code to your phone_comparison.py file:
# Define smartphone data
phones = [
{
"name": "iPhone 17e",
"price": 699,
"screen_size": 6.1,
"camera": "12MP",
"battery": 3200,
"os": "iOS 18"
},
{
"name": "Google Pixel 10a",
"price": 599,
"screen_size": 6.4,
"camera": "50MP",
"battery": 4000,
"os": "Android 14"
},
{
"name": "Samsung Galaxy A56",
"price": 549,
"screen_size": 6.7,
"camera": "64MP",
"battery": 5000,
"os": "Android 13"
}
]
Why we do this: This creates a structured way to store information about each phone. Think of it like a table in a spreadsheet, where each phone is a row and each feature is a column. This makes it easy to organize and compare data.
Step 5: Create a Function to Display Phone Information
Add this function to your code after the phone data:
def display_phone_info(phone):
print(f"Name: {phone['name']}")
print(f"Price: ${phone['price']}")
print(f"Screen Size: {phone['screen_size']} inches")
print(f"Camera: {phone['camera']}")
print(f"Battery: {phone['battery']} mAh")
print(f"Operating System: {phone['os']}")
print("-" * 30)
Why we do this: Functions help us avoid repeating the same code. This function will display all the information about one phone in a nicely formatted way, which we'll use multiple times.
Step 6: Create a Function to Compare Phones
Now add this function to compare the phones:
def compare_phones():
print("Smartphone Comparison Tool")
print("=" * 30)
for phone in phones:
display_phone_info(phone)
# Find best phone by battery life
best_battery = max(phones, key=lambda x: x['battery'])
print(f"Phone with best battery life: {best_battery['name']}")
# Find cheapest phone
cheapest = min(phones, key=lambda x: x['price'])
print(f"Cheapest phone: {cheapest['name']}")
Why we do this: This function runs our comparison by displaying all phones and then finding the best ones based on specific criteria like battery life or price. The lambda function is a shortcut to tell Python which value to compare.
Step 7: Add the Main Execution Code
Add this final code at the bottom of your file:
# Main execution
if __name__ == "__main__":
compare_phones()
Why we do this: This tells Python to run the comparison function only when you directly run this file, not when you import it into another program.
Step 8: Run Your Program
Save your file and open your terminal or command prompt. Navigate to your project folder and run:
python phone_comparison.py
You should see output showing all three phones with their features, plus which one has the best battery and which is cheapest.
Step 9: Enhance Your Tool with User Input
Replace your current compare_phones() function with this enhanced version:
def compare_phones():
print("Smartphone Comparison Tool")
print("=" * 30)
for phone in phones:
display_phone_info(phone)
# Ask user for a specific phone
print("\nWould you like to see a specific phone? Enter the name or 'all' for all phones:")
user_input = input().strip()
if user_input.lower() == 'all':
print("\nAll phones displayed above")
else:
# Find and display specific phone
found_phone = next((phone for phone in phones if phone['name'].lower() == user_input.lower()), None)
if found_phone:
print("\nDetailed Information:")
display_phone_info(found_phone)
else:
print("Phone not found. Showing all phones.")
Why we do this: This makes your tool interactive by letting users ask for specific phones, making it more useful for real-world comparisons.
Step 10: Test Your Enhanced Tool
Save your updated file and run it again:
python phone_comparison.py
Try typing 'iPhone 17e' when prompted to see specific information about that phone.
Summary
In this tutorial, you've created a smartphone comparison tool that organizes and displays information about different phones. You learned how to:
- Store data in Python lists and dictionaries
- Create reusable functions to display information
- Use Python's built-in functions like
max()andmin()for comparisons - Make your program interactive with user input
This project demonstrates how simple Python code can help you make informed decisions about technology purchases, just like the real-world comparison mentioned in the news article about the iPhone 17e, Pixel 10a, and Galaxy A56.


