1.
Program to Display Message on Screen
This program displays multiple messages using the print() function.
print("Welcome to Python Programming")
print("This program demonstrates")
print("how to display messages")
print("on the screen using Python")
2. Program Using Operators
This program demonstrates arithmetic, logical, and bitwise operators.
# Arithmetic Operators
a = 20
b = 10
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Modulus:", a % b)
# Logical Operators
x = True
y = False
print("x and y:", x and y)
print("x or y:", x or y)
print("not x:", not x)
# Bitwise Operators
m = 6
n = 3
print("m & n:", m & n)
print("m | n:", m | n)
print("m ^ n:", m ^ n)
print("m << 1:", m << 1)
print("m >> 1:", m >> 1)
3. Calculator Program
This program performs basic calculator operations using user input.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Addition =", num1 + num2)
print("Subtraction =", num1 - num2)
print("Multiplication =", num1 * num2)
if num2 != 0:
print("Division =", num1 / num2)
else:
print("Division by zero not possible")
4. Conditional Statements
This program demonstrates if, if-else, and nested if statements.
num = int(input("Enter a number: "))
# if statement
if num > 0:
print("Number is positive")
# if-else statement
if num % 2 == 0:
print("Number is even")
else:
print("Number is odd")
# Nested if
if num >= 0:
if num < 10:
print("Number is between 0 and 9")
else:
print("Number is 10 or greater")
else:
print("Number is negative")
5. Looping Statements
This program demonstrates while loop, for loop, and nested loops.
# while loop
i = 1
while i <= 5:
print("While Loop Value:", i)
i += 1
# for loop
for j in range(1, 6):
print("For Loop Value:", j)
# Nested loops
for x in range(1, 4):
for y in range(1, 4):
print("x =", x, "y =", y)
6. List Operations
This program demonstrates creation, access, update, and deletion of lists.
# Create list
numbers = [10, 20, 30, 40]
# Access list elements
print("First element:", numbers[0])
print("Last element:", numbers[-1])
# Add elements
[Link](50)
[Link](2, 25)
# Remove elements
[Link](20)
[Link]()
print("Updated list:", numbers)
# Delete list
del numbers
7. Tuple Operations
This program demonstrates tuple operations.
# Create tuple
data = (1, 2, 3, 4)
# Access tuple
print("Second element:", data[1])
# Update tuple by converting to list
temp = list(data)
[Link](5)
data = tuple(temp)
print("Updated tuple:", data)
# Delete tuple
del data
8. Set Operations
This program demonstrates set operations.
# Create set
my_set = {1, 2, 3, 4}
# Access set
for item in my_set:
print("Set element:", item)
# Add and remove elements
my_set.add(5)
my_set.discard(2)
print("Updated set:", my_set)
# Delete set
del my_set
9. Dictionary Operations
This program demonstrates dictionary operations.
# Create dictionary
student = {
"name": "Rahul",
"age": 18,
"course": "Python"
}
# Access dictionary
print("Name:", student["name"])
# Update dictionary
student["age"] = 19
student["grade"] = "A"
# Display dictionary
for key, value in [Link]():
print(key, ":", value)
# Delete dictionary
del student
10. Math Built-in Functions
This program demonstrates math built-in functions.
import math
number = 16
print("Square root:", [Link](number))
print("Power:", [Link](2, 4))
print("Factorial:", [Link](6))
print("Ceil:", [Link](4.3))
print("Floor:", [Link](4.7))
print("Value of Pi:", [Link])