Report File 12
Report File 12
Index
Sr no. Program Page no
1 Checking for Palindrome word 1
2 Sorting list without using sort function 2
3 Inserting an Element in a List 3
4 Prime Number Check 4
5 Generate a Multiplication Table 5
6 Check if a Number is Armstrong 6
7 Find the Factorial of a Number 7
8 Calculate the Sum of Digits of a Number 8
9 Check if a Number is Perfect 9
10 Check if a Number is Perfect square 10
11 Choice-Based Stack Program 11
19 Deleting data 22
1
a = "reviver"
is_palindrome =
True
if is_palindrome:
print(f"'{a}' is a
palindrome") else:
print(f"'{a}' is not a palindrome")
output:
1
1
1
for i in range(len(a)):
min_index = i
for j in range(i + 1, len(a)):
if a[j] < a[min_index]:
min_index = j
a[i], a[min_index] = a[min_index], a[i]
print("Sorted array:", a)
output:
2
1
a = [1, 2, 4, 5, 6]
b = 3
for i in
range(len(a)): if
b < a[i]:
a.insert(i,b)
break
else:
a.append(new_element)
print("Updated list:", a)
output:
1
3
1
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
else:
is_prime = False
if is_prime:
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")
output:
4
1
num = 7
limit = 10
output:
5
1
def is_armstrong(num):
num_str = str(num)
n = len(num_str)
num = 153
if is_armstrong(num):
print(f"{num} is an Armstrong number")
else:
print(f"{num} is not an Armstrong number")
output:
6
1
num = 5
print(f"Factorial of {num} is {factorial(num)}")
output:
7
1
def sum_of_digits(num):
total = 0
while num > 0:
total += num % 10
num //= 10
return total
number = 12345
print(f"Sum of digits of {number} is {sum_of_digits(number)}")
output:
8
1
divisors_sum = 0
for i in range(1, n):
if n % i == 0:
divisors_sum += i
return divisors_sum == n
num = 28
if is_perfect_number(num):
print(f"{num} is a perfect number")
else:
print(f"{num} is not a perfect number")
output:
9
1
num = 49
if is_perfect_square(num):
print(f"{num} is a perfect square")
else:
print(f"{num} is not a perfect square")
output:
10
1
def push():
element = int(input("Enter element to push: "))
stack.append(element)
print(f"{element} pushed to stack")
def pop():
if not stack:
print("Stack is empty!")
else:
popped_element = stack.pop()
print(f"{popped_element} popped from stack")
def display():
if not stack:
print("Stack is empty!")
else:
print("Stack elements:", stack)
while True:
print("\n1. Push\n2. Pop\n3. Display\n4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
push()
elif choice == 2:
pop()
elif choice == 3:
display()
elif choice == 4:
break
else:
print("Invalid choice, please try again.")
11
1
output:
12
1
return word_count
except FileNotFoundError:
return "File not found!"
filename = "example.txt"
word_count =
count_words(filename) if
isinstance(word_count, dict):
print("Word counts:", word_count)
1
13
1
else:
print(word_count)
output:
14
1
Import pickle
def write_binary_file(filename, data):
with open(filename, 'wb') as file:
pickle.dump(data, file)
print(f"Data written to {filename}")
def read_binary_file(filename):
try:
with open(filename, 'rb') as file:
data = pickle.load(file)
return data
except FileNotFoundError:
return "File not found!"
numbers = [10, 20, 30, 40, 50]
filename = "numbers.dat"
write_binary_file(filename, numbers)
result = read_binary_file(filename)
if isinstance(result, list):
print("Data read from file:", result)
else:
print(result)
15
1
output:
16
1
17
1
output:
18
1
output:
19
1
output:
20
1
output:
USE bot;
SELECT Name, Age FROM Students WHERE Age > 20;
output:
21
1
USE bot;
SELECT Name, Age FROM Students WHERE Age BETWEEN 20 AND 22;
output:
22
1
Execution:
Output:
23
1
Execution:
24
1
Output:
25
1
26
1
Output:
27
1
Output:
28