π Project Phase Begins: From Syntax to Solutions
We have finished the "Python Basics" series! π We learned about variables, if statements, functions, and input handling.
But syntax alone doesn't make you a developer. Building things does.
From today, I will start the "Mini-Project Series." We will take the concepts we learned and apply them to create actual working applications.
Our first project is a classic: A Currency Converter.
We will build it in two ways:
- Console Version: Using basic Python logic.
- Web App Version: Using Streamlit to give it a Graphical User Interface (GUI).
1οΈβ£ The Goal: CHF β EUR Converter
Living in or traveling near Switzerland often means dealing with two currencies: Swiss Francs (CHF) and Euros (EUR).
Instead of Googling the rate every time, let's write a script that does the math for us.
Key Logic:
- CHF to EUR: Multiply by the rate.
- EUR to CHF: Divide by the rate.
[Image of currency exchange concept]
2οΈβ£ Step 1: The Console Version (Backend Logic)
First, let's implement the core logic using input() and print(). This is the raw logic without a fancy interface.
π converter.py
# Fixed exchange rate (Simulated)
rate = 1.05
choice = input("Select an option: 1) CHF β EUR | 2) EUR β CHF: ")
if choice == "1":
print("=== Currency Converter ===")
# Get user input and convert string to float
amount = float(input("Enter amount in CHF: "))
result = amount * rate
print(f"EUR: {result:.2f}")
elif choice == "2":
print("=== Currency Converter ===")
amount = float(input("Enter amount in EUR: "))
# Division for reverse conversion
result = amount / rate
print(f"CHF: {result:.2f}")
else:
print("Invalid option.")
What we applied here:
-
input()to get user data. -
float()to handle decimal numbers (money). -
if-elif-elseto handle the direction of conversion.
3οΈβ£ Step 2: The Web Version (Frontend with Streamlit)
Console apps are great for logic, but users prefer buttons and text boxes.
We don't need to learn HTML/CSS yet. We can use a Python library called Streamlit to turn our script into a web app in seconds.
π converter_streamlit.py
import streamlit as st
# 1. Title
st.title("π± Currency Converter (CHF β EUR)")
rate = 1.05 # Exchange rate
# 2. Radio button for user choice
option = st.radio(
"Select conversion direction:",
("CHF β EUR", "EUR β CHF")
)
# 3. Numeric Input
amount = st.number_input("Enter amount:", min_value=0.0, format="%.2f")
# 4. Button to trigger calculation
if st.button("Convert"):
if option == "CHF β EUR":
result = amount * rate
st.success(f"{amount} CHF = {result:.2f} EUR")
else:
result = amount / rate
st.success(f"{amount} EUR = {result:.2f} CHF")
4οΈβ£ Comparison: Console vs. Streamlit
| Feature | Console Version (input) |
Web Version (streamlit) |
|---|---|---|
| Interface | Black terminal window | Clean Web Browser UI |
| Input | Typing text and pressing Enter | Clicking buttons and typing boxes |
| Feedback | Text output (print) |
Visual boxes (st.success) |
| Difficulty | Very Easy | Easy (Requires library installation) |
5οΈβ£ How to Run This Project
If you want to try this code on your machine:
1. Console Version
Simply run it with Python:
python3 converter.py
2. Streamlit Version
First, install the library:
pip install streamlit
Then run the app:
streamlit run converter_streamlit.py
A browser tab will open automatically!
π§ Future Improvements
This project is a great start, but it has one limitation: The exchange rate is hardcoded (fixed at 1.05).
In a real-world application, exchange rates change every second.
Next steps for this project:
- Connect to a Real-time API to fetch the current rate.
- Add Multi-currency support (USD, JPY, KRW).
- Deploy the web app so others can use it via a URL.
This was a simple start to our project journey. Stay tuned for the next project where we tackle more complex logic!
Github Repository: [Link to your actual Github Repo]
Top comments (0)