Python Learning – Day 4: Conditional Statements (if, else, elif)

Python Learning – Day 4: Conditional Statements (if, else, elif)

Introduction

Welcome to Day 4 of my Python learning journey.
In this lesson, I learned how Python makes decisions using conditional statements such as if, else, and elif.

Conditional statements are extremely important in programming because real-life applications constantly make decisions based on conditions.


📚 Topics Covered in Day 4

In this lesson, I learned:

  • What are conditional statements
  • How if works in Python
  • How if-else controls program flow
  • How elif handles multiple conditions
  • Using conditions with user input

🔀 What Are Conditional Statements?

Conditional statements allow a program to execute different code blocks based on conditions.

In simple words:

If a condition is true → do something
Else → do something else


🧠 Simple if Example

age = 20

if age >= 18:
    print("You can vote")

This code checks whether a person is eligible to vote.


🔄 if – else Example

age = 16

if age >= 18:
    print("You can vote")
else:
    print("You cannot vote")

Here, Python makes a decision based on the value of age.


🧮 Real-Life Example: Pass or Fail

marks = 35

if marks >= 40:
    print("Pass")
else:
    print("Fail")

This logic is commonly used in school result systems.


➕ Multiple Conditions Using elif

marks = 75

if marks >= 90:
    print("Excellent")
elif marks >= 60:
    print("Good")
elif marks >= 40:
    print("Pass")
else:
    print("Fail")

Python checks the conditions from top to bottom and executes the first true condition.


🧾 Real-Life Program: Student Result System

name = input("Enter your name: ")
marks = int(input("Enter your marks: "))

if marks >= 90:
    print(f"{name}, your result is: Excellent")
elif marks >= 60:
    print(f"{name}, your result is: Good")
elif marks >= 40:
    print(f"{name}, your result is: Pass")
else:
    print(f"{name}, your result is: Fail")

This program behaves like a real-world student result evaluation system.


🌍 Why Conditional Statements Are Important

Conditional statements are used in:

  • Login systems
  • Eligibility checks
  • Exam result processing
  • Banking and finance applications
  • Decision-based automation

Without conditional logic, programs would not be able to make decisions.


✅ What I Learned Today

  • How to use if, else, and elif
  • How Python makes decisions
  • How to apply logic to real-life problems
  • How to create interactive decision-based programs

This lesson helped me understand the foundation of decision-making in Python.


🔜 Next Lesson (Day 5)

In Day 5, I will learn about:

  • Loops in Python
  • Repeating tasks automatically
  • Real-life loop examples

📢 Final Note

This Python learning series is written for beginners.
Anyone who wants to learn Python step by step can follow these posts.

Thank you for reading 🚀

Python Learning – Day 3: Strings and User Input

Python Learning – Day 3: Strings and User Input

Introduction

Welcome to Day 3 of my Python learning journey.
In this lesson, I learned how Python interacts with users using strings and user input.

Most real-world applications need to communicate with users, and this lesson explains how Python takes input, processes it, and displays meaningful output.


📚 Topics Covered in Day 3

In this lesson, I learned:

  • What are strings in Python
  • How to take user input using input()
  • How to convert input into numbers
  • How to format output using f-strings

🔤 What Is a String in Python?

A string is a sequence of characters used to store text.
In Python, strings are written inside double quotes " " or single quotes ' '.

Example:

message = "Hello, Python"
print(message)

Output:

Hello, Python

Strings are commonly used for:

  • Names
  • Messages
  • User input
  • Text display

🧾 Taking User Input in Python (input())

The input() function allows Python to receive data from the user.

Example:

name = input("Enter your name: ")
print("Hello", name)

Output:

Enter your name: Hiranmoy
Hello Hiranmoy

By default, input() always returns a string.


🔢 Converting Input into Numbers

When we need to perform calculations, we must convert user input into numbers using int().

Example:

age = int(input("Enter your age: "))
print("After 5 years, your age will be", age + 5)

Output:

Enter your age: 22
After 5 years, your age will be 27

🧠 Formatting Output Using f-Strings

Python provides f-strings to format output easily.

Example:

name = input("Enter your name: ")
city = input("Enter your city: ")

print(f"I am {name} and I live in {city}")

Output:

I am Hiranmoy and I live in Haldia

f-strings make code cleaner and easier to read.


🏗️ Real-Life Example: Online Form

The following program simulates a simple online form:

name = input("Enter your name: ")
age = int(input("Enter your age: "))
profession = input("Enter your profession: ")
city = input("Enter your city: ")

print("\n--- User Details ---")
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Profession: {profession}")
print(f"City: {city}")

This program behaves like filling an online registration form.


🌍 Why This Lesson Is Important

User input and strings are essential in:

  • Login systems
  • Registration forms
  • Chat applications
  • Interactive software

This lesson is a foundation for building real-world Python applications.


✅ What I Learned Today

  • How to work with strings
  • How to take user input
  • How to convert input into numbers
  • How to format output using f-strings

This lesson helped me build interactive Python programs.


🔜 Next Lesson (Day 4)

In Day 4, I will learn about:

  • Conditional statements (if, else)
  • Decision making in Python
  • Real-life logic examples

📢 Final Note

This Python learning series is written for beginners.
Anyone who wants to learn Python step by step can follow these posts.

Thank you for reading 🚀

Python Learning – Day 2: Operators and Real-Life Calculations

Python Learning – Day 2: Operators and Real-Life Calculations

Introduction

Welcome to Day 2 of my Python learning journey.
In this lesson, I learned how Python performs mathematical calculations using operators.

Operators are very important in programming because almost every real-world application involves calculations such as bills, salary, discounts, and expenses.


📚 Topics Covered in Day 2

In this lesson, I learned:

  • What are operators in Python
  • Arithmetic operators
  • How Python performs calculations
  • Real-life examples like shopping bills and discounts

🧮 What Are Operators in Python?

Operators are symbols that perform operations on values and variables.

Python operators help us to:

  • Add numbers
  • Subtract values
  • Multiply quantities
  • Divide amounts
  • Find remainders

🔢 Arithmetic Operators in Python

OperatorPurposeExample
+Addition10 + 5
-Subtraction10 – 5
*Multiplication10 * 5
/Division10 / 5
%Modulus (remainder)10 % 3

🏪 Real-Life Example: Shopping Bill

Let’s calculate the total cost of buying rice.

Python Code Example:

rice_price = 60
quantity = 3

total_price = rice_price * quantity
print("Total price =", total_price)

Output:

Total price = 180

This example is similar to calculating a bill in a grocery store.


🏷️ Discount Calculation Example

Now let’s apply a discount to the total price.

Python Code:

rice_price = 60
quantity = 3
discount = 5  # percent

total_price = rice_price * quantity
final_price = total_price - (total_price * discount / 100)

print("Rice price =", rice_price)
print("Quantity =", quantity)
print("Total price =", total_price)
print("Discount =", discount, "%")
print("Final price after discount =", final_price)

Output:

Rice price = 60
Quantity = 3
Total price = 180
Discount = 5 %
Final price after discount = 171.0

🔍 Modulus Operator (%) – Real-Life Meaning

The modulus operator % returns the remainder after division.

Example:

print(10 % 3)

Output:

1

Real-Life Use Case:

If 10 items are divided among 3 people, 1 item will remain.


🌍 Why Operators Are Important?

Operators are used everywhere in real-world applications:

  • Shopping and billing systems
  • Salary calculation
  • Expense tracking
  • Banking applications

Without operators, programming would not be possible.


✅ What I Learned Today

  • How Python performs calculations
  • How to use arithmetic operators
  • How to calculate bills and discounts
  • How Python helps in real-life problem solving

This lesson helped me understand how Python works like a smart calculator.


🔜 Next Lesson (Day 3)

In Day 3, I will learn about:

  • Strings in Python
  • Taking user input using input()
  • Creating simple interactive programs

📢 Final Note

This Python learning series is designed for beginners.
Anyone who wants to learn Python step by step can follow these posts.

Thank you for reading 🚀