Basic Python Programs
Welcome to the final lesson of the Beginner Level in Python! You have learned variables, data types, operators, input/output, conditionals, loops, strings, lists, tuples, dictionaries, and sets. Now it’s time to apply everything in simple programs and a small beginner-friendly mini project.
These examples help you connect your theoretical knowledge with real problem-solving skills, which is the foundation of becoming confident in Python programming.
1. Hello World Program
The most basic Python program prints a simple message to the screen.
This ensures everything is working correctly and introduces the print() function.
print("Hello, World!")
2. Add Two Numbers
This program demonstrates how to use variables and the addition operator to compute a result.
a = 15
b = 25
sum = a + b
print("Sum:", sum)
3. Area of a Rectangle
Formula for the area: Area = Length × Width This program is a perfect example of using arithmetic operations in real life.
length = 12
width = 7
area = length * width
print("Area of Rectangle:", area)
4. Simple Interest Calculator
Formula: Simple Interest = (Principal × Rate × Time) / 100
P = 8000
R = 6
T = 3
SI = (P * R * T) / 100
print("Simple Interest:", SI)
5. Check If a Number Is Even or Odd
A number is even if divisible by 2, else odd.
This program uses the modulus operator %.
num = 14
if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")
6. Largest of Three Numbers
A great program to understand conditionals and logical comparisons.
a = 45
b = 67
c = 52
if a >= b and a >= c:
print("Largest:", a)
elif b >= a and b >= c:
print("Largest:", b)
else:
print("Largest:", c)
7. Temperature Converter (Celsius → Fahrenheit)
Formula: Fahrenheit = (Celsius × 9/5) + 32
celsius = 30
fahrenheit = (celsius * 9/5) + 32
print("Fahrenheit:", fahrenheit)
8. Swap Two Numbers
Python provides a clean single-line swap — no temporary variable needed.
a = 5
b = 12
a, b = b, a
print("a =", a)
print("b =", b)
9. Count Vowels in a String
A useful program that teaches iteration and membership testing using in.
text = "dataplexa python course"
vowels = "aeiou"
count = 0
for ch in text:
if ch in vowels:
count += 1
print("Vowel Count:", count)
10. Reverse a Number
A classic logic-building program using loops and digit extraction.
num = 753
reverse_num = 0
while num > 0:
digit = num % 10
reverse_num = reverse_num * 10 + digit
num //= 10
print("Reversed Number:", reverse_num)
🧠 Beginner Level Mini Project – “Simple Billing System”
This mini project combines variables, input/output, arithmetic operations, conditionals, and formatting. It simulates a small billing system used in basic stores.
Goal: Create a program that:
- Takes item name, price, and quantity as input
- Calculates total amount
- Adds GST
- Prints a clean bill summary
Mini Project Code
# Simple Billing System (Beginner Mini Project)
item = input("Enter item name: ")
price = float(input("Enter price of item: "))
qty = int(input("Enter quantity: "))
gst_rate = 0.18
subtotal = price * qty
gst = subtotal * gst_rate
total = subtotal + gst
print("\n------ BILL SUMMARY ------")
print("Item:", item)
print("Price:", price)
print("Quantity:", qty)
print("Subtotal:", subtotal)
print("GST (18%):", gst)
print("Total Amount:", total)
print("--------------------------")
This is your first complete functional program. Beginner Level is officially complete — now you're ready for the Intermediate Level.
📝 Practice Exercises
- Write a program to calculate the square and cube of a number.
- Write a program to convert kilometers into miles.
- Write a program to find the average of five numbers.
- Write a program to display multiplication table of any number.
- Write a program to check whether a year is a leap year.
✅ Practice Answers
Answer 1:
num = 4
print("Square:", num ** 2)
print("Cube:", num ** 3)
Answer 2:
km = 10
miles = km * 0.621371
print("Miles:", miles)
Answer 3:
a, b, c, d, e = 10, 20, 30, 40, 50
avg = (a + b + c + d + e) / 5
print("Average:", avg)
Answer 4:
num = 7
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Answer 5:
year = 2024
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")