Real-World Mini Projects
Lesson Overview
Your first practical coding experience! This lesson combines all your Python fundamentals - variables, data types, strings, conditions, loops, and dictionaries - into three realistic Indian scenarios. Each project includes detailed comments showing exactly how the concepts you've mastered work together in real applications.
Lesson Content
Time to Code! Three Practical Python Projects
Welcome to Your First Real Programming Challenge!
Remember all those concepts you learned? Variables, data types, f-strings, conditions, loops, and dictionaries? Now it's time to see them work together in real Indian scenarios! Each project has detailed comments showing you exactly which concepts are being used and why.
Project 1: Banking Portal for Customer
Scenario: Track your monthly expenses in rupees, categorize spending, and calculate savings for Diwali shopping!
Requirement : You want to build a simple banking system for a customer. After logging in with a username and password, the customer should be able to view their basic account details such as name and current balance. They must also be able to perform core operations like withdrawing money and depositing money into their account. In addition, the system should provide a way to calculate the interest that will be earned on the current balance for the next 12 months
From the requirements, the system can be broken into these clear executable tasks:
- Implementation of login : Allow the customer to log in using a name and password.
- Display customer details : Once logged in, show the customer’s name and current account balance.
- Support money operations : Provide options to deposit money into the account and withdraw money from it with proper checks.
- Interest calculation for 12 months : Add a feature to calculate and display the interest on the current balance for each of the next 12 months.
1. Implementation of login
To keep the system closer to a real-world scenario, make a few clear assumptions: use a fixed default password for login, and if the customer enters the wrong password, the system will give them up to five attempts before denying access. Once the customer successfully logs in, automatically initialize their account with a starting balance of 1,00,000 rupees
# Initialize empty dictionary to hold customer data
customer_data = {} # Will store keys like: name, balance
DEFAULT_PASSWORD = "1234" # Using a Default Password for every Customer
print("Welcome to ByLearning Demo Bank")
customer_name = input("Enter your name: ")
customer_name = customer_name.strip() # use Strip method to remove un-wanted space in the given input
customer_name = customer_name.capitalize() # use capitalize method to make the first letter as CAPITAL
# Use a while loop to keep asking for correct password
counter = 1 # Using the couter variable to keep track of no of attempts
while True:
entered_password = input("Enter your banking password : ") # Using input function take the password from user
entered_password = entered_password.strip() # use Strip method to remove un-wanted space in the given input
print(f'You have entered Passwrod as { entered_password }') # Using F-String to show the entered password by User
# If - else ladder to check the login conditons
if entered_password == DEFAULT_PASSWORD:
print("Login successful!")
break # If Passowrd matches, Login the Customer
else:
if counter == 5:
# mutli line statement to show the User a detailed message
print('''
Incorrect Passowrd was entered 5 times.
Your account will be blocked.
Contact Bank Support Team to un-block your account
''')
break # Go out of loop
else:
print("Incorrect password. Please try again ") # If the retry count is less than 5, show this
counter = counter+1 # Incremente the Counter
# Once user logs in set Name and default balance = 1,00,000 INR
customer_data["name"] = customer_name
customer_data["balance"] = 100000 # 1 Lakh INR2. Display customer details
Customer details display is a reusable function because customers need to see their updated name and balance after login, deposits, withdrawals, and interest checks. It ensures consistent professional formatting every time without repeating code
# Example usage after login:
# customer_data = {"name": "Rahul Sharma", "balance": 100000}
def get_customer_info(customer_data) :
name = customer_data["name"]
balance_formatted = customer_data['balance']
print("="*40) # sting repetitionto make a visual differentiation
print("🏦 BYLEARNING DEMO BANK - CUSTOMER PROFILE")
print("="*40)
print(f"Customer Name : {name}")
print(f"Current Balance: ₹{balance_formatted}")
print("="*40)
# Output:
# ========================================
# BYLEARNING DEMO BANK - CUSTOMER PROFILE
# ========================================
# Customer Name : Rahul Sharma
# Current Balance: ₹100000
# ========================================3. Support money operations
Withdrawals and deposits are independent, reusable operations that can be implemented as standalone functions. These operations can be performed multiple times (n times) by the customer without needing to recreate the logic each time, making them perfect candidates for functions that can be called repeatedly during a banking session.
# Function for deposit
def deposit(customer_data, amount):
# Basic validation
if amount <= 0:
print("Deposit amount must be greater than zero.")
return
# Update balance
customer_data["balance"] += amount
print(f"Successfully deposited ₹{amount}.")
print(f"New balance: ₹{customer_data['balance']}")
# Function for withdrawal
def withdraw(customer_data, amount):
if amount <= 0:
print("Withdrawal amount must be greater than zero.")
return
if amount > customer_data["balance"]:
print("Insufficient balance. Transaction cancelled.")
return
customer_data["balance"] -= amount
print(f"Successfully withdrew ₹{amount}.")
print(f"New balance: ₹{customer_data['balance']}")
💬 Comments (0)
Login to join the discussion
No comments yet. Be the first to share your thoughts!