q)python program to create ,append andremove list in python
using numpy
import numpy as np
# -----------------------------
# 1. CREATE a NumPy array
# -----------------------------
arr = [Link]([10, 20, 30, 40])
print("Original Array:", arr)
# -----------------------------
# 2. APPEND elements to array
# -----------------------------
arr = [Link](arr, 50) # append single value
arr = [Link](arr, [60, 70]) # append multiple values
print("After Append:", arr)
# -----------------------------
# 3. REMOVE elements from array
# -----------------------------
# Remove element at index 2 (i.e., value 30)
arr = [Link](arr, 2)
print("After Removing index 2:", arr)
# Remove multiple indices
arr = [Link](arr, [0, 3]) # remove index 0 and 3
print("After Removing multiple indices:", arr)
OUTPUT
Original Array: [10 20 30 40]
After Append: [10 20 30 40 50 60 70]
After Removing index 2: [10 20 40 50 60 70]
After Removing multiple indices: [20 40 60]
Q) TANSPOSE OF A MATRIX WITHOUT USING BUILTIN FUNCTION
# Transpose of a matrix without using built-in functions
# Sample matrix
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
# Get number of rows and columns
rows = len(matrix)
cols = len(matrix[0])
# Create an empty transpose matrix (cols x rows)
transpose = []
for i in range(cols):
new_row = []
for j in range(rows):
new_row.append(matrix[j][i]) # swap index
[Link](new_row)
# Print the transpose
print("Original Matrix:")
for row in matrix:
print(row)
print("\nTranspose Matrix:")
for row in transpose:
print(row)
PYTHON PROGRAM TO CREATE CONCATENATE AND PRINT A STRING AND TO
ACCESS A SUBSTRING FROM A GIVEN STRING
# Create two strings
str1 = "Hello"
str2 = "World"
# Concatenate strings
result = str1 + " " + str2
# Print the final concatenated string
print("Concatenated String:", result)
# -------- Accessing a Substring --------
# Example string
text = "Welcome to Python Programming"
# Extract substring: characters from index 11 to 17
substring = text[11:17]
# Print substring
print("Original String:", text)
print("Substring (index 11 to 17):", substring)
OUTPUT
Concatenated String: Hello World
Original String: Welcome to Python Programming
Substring (index 11 to 17): Python
Q) PROGRAM TO CHECK PALINDROME OR NOT WITHUSING STRING
FUNCTIONS
text = input("Enter a string: ")
# Convert the string to lowercase
text = [Link]()
# Reverse the string using a loop
rev = ""
for i in range(len(text)-1, -1, -1):
rev += text[i]
# Check palindrome
if text == rev:
print("It is a Palindrome")
else:
print("Not a Palindrome")
Q) PROGRAM TO CHECK PALINDROME OR NOT WITHOUT USING STRING
FUNCTIONS
# Program to check palindrome using list (no string functions)
text = input("Enter a string: ")
# Convert string to list of characters manually
char_list = []
for ch in text:
char_list.append(ch)
# Create reversed list manually
rev_list = []
for i in range(len(char_list)-1, -1, -1):
rev_list.append(char_list[i])
# Check palindrome
if char_list == rev_list:
print("It is a Palindrome")
else:
print("Not a Palindrome")
Q) PYTHON PROGRAM TO REMOVE DUPLICATES FROM A LIST OF N INPUT
NUMBERS
# Program to remove duplicates from a list of N input numbers
n = int(input("Enter how many numbers: "))
numbers = []
print("Enter the numbers:")
for i in range(n):
num = int(input())
[Link](num)
# Remove duplicates manually
unique_list = []
for num in numbers:
if num not in unique_list:
unique_list.append(num)
print("List without duplicates:", unique_list)