Python Basic Intermediate Programs
Python Basic Intermediate Programs
Hello World
print("Hello, World!")
Basic Arithmetic
a = 10
b = 20
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
If-else Condition
num = 10
if num % 2 == 0:
print("Even")
else:
print("Odd")
For Loop
for i in range(5):
print("Number:", i)
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
Page 1
Basic and Intermediate Python Programs
List Operations
my_list = [1, 2, 3]
my_list.append(4)
String Manipulation
print("Upper:", text.upper())
print("Lower:", text.lower())
File Handling
print(file.read())
def bubble_sort(arr):
n = len(arr)
for i in range(n):
return arr
Page 2
Basic and Intermediate Python Programs
class Dog:
self.name = name
def bark(self):
d = Dog("Buddy")
d.bark()
Page 3