Python Programs for PSEB Students 2026 | Class 11 & 12 Computer Science


Complete Python programs for PSEB Class 11 & 12 Computer Science students. Step-by-step full codes with explanations in English and Punjabi. Covers basics, if-else, loops, patterns, prime, Fibonacci and syllabus practicals.

PSEB 2026 Computer Science - Python Beginner Programs for Students

🐍 Python Programs for PSEB 2026 Computer Science

Class 11 & 12 Students | Step-by-step Full Programs
Aligned with PSEB Syllabus 2026-27 (Basic Concepts, Data Types, Operators, Control Statements, Practical Activities)

How to use: Copy the code into IDLE, Thonny, or any Python IDE. Run it and practice modifying the values. Best learning order: print() → Variables → input() → Data Types → Operators → if/else → Loops → Patterns → Advanced checks.

1. Absolute Basics (Chapter 2)

Program 1: First Python Program - Hello World Beginner

The simplest program. Shows how to display text using print().
# My First Python Program
print("Hello World")
print("Welcome to PSEB Computer Science 2026")
Hello World Welcome to PSEB Computer Science 2026

Program 2: Print Your Name and Details

Using variables to store and print student information.
# Program to print student details
name = "Dishant Singh"
class_name = "11th"
school = "Govt. Senior Secondary School"

print("Name:", name)
print("Class:", class_name)
print("School:", school)
print("Subject: Computer Science")
Name: Dishant Singh Class: 11th School: Govt. Senior Secondary School Subject: Computer Science

Program 3: Comments and Variables

Demonstrates single-line comments (#) and multi-line comments. Variables store data.
# This is a single-line comment
"""
This is a multi-line comment
Used for longer explanations
"""

# Variables
student_name = "Aman"      # String
age = 16                   # Integer
marks = 85.5               # Float
is_pass = True             # Boolean

print("Name:", student_name)
print("Age:", age)
print("Marks:", marks)
print("Passed:", is_pass)

2. Input, Output & Operators (Chapter 3)

Program 4: Take Input from User

Using input() to get data from the keyboard. Always returns string, so use int() for numbers.
# Program to take name as input
name = input("Enter your name: ")
print("Hello", name)
print("Welcome to Python programming!")

Program 5: Add Two Numbers (Hardcoded)

# Program to add two numbers
a = 10
b = 20
sum_result = a + b
print("First number =", a)
print("Second number =", b)
print("Sum =", sum_result)
First number = 10 Second number = 20 Sum = 30

Program 6: Add Two Numbers (User Input)

Type conversion with int() because input() gives string.
# Program to add two numbers taken from user
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
sum_result = a + b
print("Sum =", sum_result)
print("Difference =", a - b)
print("Product =", a * b)
print("Quotient =", a / b)
print("Integer Division =", a // b)
print("Remainder =", a % b)
print("Power =", a ** b)

Program 7: Area of Rectangle and Circle

# Calculate area of rectangle and circle
length = float(input("Enter length of rectangle: "))
breadth = float(input("Enter breadth of rectangle: "))
rect_area = length * breadth
print("Area of Rectangle =", rect_area)

radius = float(input("Enter radius of circle: "))
circle_area = 3.14 * radius * radius
print("Area of Circle =", circle_area)

Program 8: Data Types Demonstration

# Different data types in Python
num_int = 25
num_float = 25.5
num_complex = 3 + 4j
text = "Python"
is_true = True
empty = None

print(type(num_int))
print(type(num_float))
print(type(num_complex))
print(type(text))
print(type(is_true))
print(type(empty))

3. Conditional Statements (Chapter 4)

Program 9: Even or Odd Number

Uses modulo operator (%) to check remainder.
# Check if a number is even or odd
num = int(input("Enter a number: "))

if num % 2 == 0:
    print(num, "is Even")
else:
    print(num, "is Odd")

Program 10: Absolute Value of a Number

Syllabus suggested program. Absolute value is always positive.
# Find absolute value of a number
num = float(input("Enter a number: "))

if num < 0:
    abs_value = -num
else:
    abs_value = num

print("Absolute value =", abs_value)
# Alternative: print(abs(num))

Program 11: Largest of Two Numbers

# Find largest of two numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))

if a > b:
    print("Largest is", a)
elif b > a:
    print("Largest is", b)
else:
    print("Both numbers are equal")

Program 12: Largest of Three Numbers

Syllabus practical activity.
# Find largest of three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

if a >= b and a >= c:
    largest = a
elif b >= a and b >= c:
    largest = b
else:
    largest = c

print("The largest number is", largest)

Program 13: Check Divisibility

Check if a number is divisible by another.
# Check divisibility
num = int(input("Enter a number: "))
divisor = int(input("Enter divisor: "))

if num % divisor == 0:
    print(num, "is divisible by", divisor)
else:
    print(num, "is not divisible by", divisor)

Program 14: Voting Eligibility

# Check if person is eligible to vote
age = int(input("Enter your age: "))

if age >= 18:
    print("You are eligible to vote")
else:
    print("You are not eligible to vote")
    print("You can vote after", 18 - age, "years")

4. Loops (for and while)

Program 15: Print Numbers 1 to 5 using for loop

# Simple for loop
print("Numbers from 1 to 5:")
for i in range(1, 6):
    print(i)
Numbers from 1 to 5: 1 2 3 4 5

Program 16: Sum of First N Natural Numbers

# Sum of first n numbers
n = int(input("Enter a number: "))
total = 0

for i in range(1, n + 1):
    total = total + i

print("Sum of first", n, "numbers =", total)

Program 17: Factorial of a Number

Syllabus suggested program. Factorial of 5 = 5×4×3×2×1 = 120
# Calculate factorial
n = int(input("Enter a positive number: "))
fact = 1

for i in range(1, n + 1):
    fact = fact * i

print("Factorial of", n, "=", fact)

Program 18: Multiplication Table

# Print multiplication table
num = int(input("Enter a number: "))

print("Multiplication Table of", num)
for i in range(1, 11):
    print(num, "x", i, "=", num * i)

Program 19: Simple Star Pattern (Right Triangle)

Using nested loops for patterns (syllabus practical).
# Right angle triangle pattern
rows = int(input("Enter number of rows: "))

for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print("*", end=" ")
    print()  # New line after each row
* * * * * * * * * * * * * * *

Program 20: While Loop - Countdown

# Countdown using while loop
count = int(input("Enter a number to countdown: "))

while count > 0:
    print(count)
    count = count - 1

print("Blast Off!")

5. Important Syllabus Practical Programs

Program 21: Check Prime Number

A number is prime if it has only two factors: 1 and itself.
# Check if a number is prime
num = int(input("Enter a number: "))

if num <= 1:
    print(num, "is not a prime number")
else:
    is_prime = True
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            is_prime = False
            break
    
    if is_prime:
        print(num, "is a Prime number")
    else:
        print(num, "is not a Prime number (Composite)")

Program 22: Fibonacci Series

Series where each number is sum of previous two: 0, 1, 1, 2, 3, 5, 8...
# Print Fibonacci series
n = int(input("How many terms? "))

a, b = 0, 1
print("Fibonacci Series:")
for i in range(n):
    print(a, end=" ")
    a, b = b, a + b
print()

Program 23: Check Palindrome Number

A number that reads the same forwards and backwards (e.g., 121).
# Check if number is palindrome
num = int(input("Enter a number: "))
original = num
reverse = 0

while num > 0:
    digit = num % 10
    reverse = reverse * 10 + digit
    num = num // 10

if original == reverse:
    print(original, "is a Palindrome")
else:
    print(original, "is not a Palindrome")

Program 24: Armstrong Number

Sum of cubes of digits equals the number (e.g., 153 = 1³+5³+3³).
# Check Armstrong number (3 digits)
num = int(input("Enter a 3-digit number: "))
original = num
sum_cubes = 0

while num > 0:
    digit = num % 10
    sum_cubes += digit ** 3
    num = num // 10

if original == sum_cubes:
    print(original, "is an Armstrong number")
else:
    print(original, "is not an Armstrong number")

Program 25: GCD of Two Numbers

Greatest Common Divisor using Euclidean algorithm.
# Find GCD of two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

while b != 0:
    a, b = b, a % b

print("GCD is", a)

6. Bonus: Simple Functions (Class 12 Preview)

Program 26: Function to Add Two Numbers

Introduction to user-defined functions (Class 12 topic).
# Simple function example
def add_numbers(x, y):
    """Function to add two numbers"""
    result = x + y
    return result

# Using the function
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum_result = add_numbers(num1, num2)
print("Sum =", sum_result)

Program 27: Simple Calculator using Functions

# Simple calculator with functions
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b != 0:
        return a / b
    else:
        return "Cannot divide by zero"

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
op = input("Enter operator (+, -, *, /): ")

if op == '+':
    print("Result =", add(a, b))
elif op == '-':
    print("Result =", subtract(a, b))
elif op == '*':
    print("Result =", multiply(a, b))
elif op == '/':
    print("Result =", divide(a, b))
else:
    print("Invalid operator")
Tips for Students:
  • Practice writing these programs yourself without looking.
  • Modify the programs — change values, add more conditions, try different patterns.
  • Use comments to explain your logic.
  • For practical file: Write neatly, include output screenshots, and add your name/roll number.
  • Next steps after mastering these: Strings, Lists, Tuples, Dictionaries (Class 12 Collections), and more functions.
Learning Order Recommended:
print() → Variables → input() → Data Types → Operators → if/else → Loops → Patterns → Practical Programs → Functions

Created for PSEB 2026 Computer Science Students | Class 11 & 12 Python Beginner Course

Practice daily. Consistency is the key to learning programming! 🚀

Save this page and print for your notebook if needed.

Complete Python programs for PSEB Class 11 & 12 Computer Science students. Step-by-step full codes with explanations in English and Punjabi. Covers basics, if-else, loops, patterns, prime, Fibonacci and syllabus practicals.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top