Python Programming PART A Lab Manual
Python Programming PART A Lab Manual
PART A
# a) Sum
total_sum = sum(numbers)
print("Sum:", total_sum)
# b) Average
average = total_sum / len(numbers)
print("Average:", average)
# c) Max
maximum = max(numbers)
print("Max:", maximum)
# d) Min
minimum = min(numbers)
print("Min:", minimum)
# e) Sort
sorted_list = sorted(numbers)
print("Sorted List:", sorted_list)
# f) Reverse
reversed_list = list(reversed(numbers))
print("Reversed List:", reversed_list)
Output:
Sum: 83
Average: 13.833333333333334
Max: 25
Min: 5
Sorted List: [5, 8, 10, 15, 20, 25]
Reversed List: [25, 15, 8, 5, 20, 10]
Output:
List after swapping elements: ['Professor', 'HOD', 'Dean']
Combined List: ['Professor', 'HOD', 'Dean', 'Mangaluru', 'Kudla', 'Dakshina
Kannada']
Output:
4. Write a python program to find tuples which have all elements divisible by k from a
list of tuples
# Output result
print("Tuples with all elements divisible by", k, "are:", result)
Output:
Tuples with all elements divisible by 5 are: [(10, 20, 30)]
Output:
Enter the value : MAASTHI AMMA
The original tuple is :
('M', 'A', 'A', 'S', 'T', 'H', 'I', ' ', 'A', 'M', 'M', 'A')
The tuple after removing duplicates :
('T', 'A', 'M', 'I', 'S', 'H', ' ')
import numpy as np
# b) Splitting arrays
split_array = np.array_split(joined_array, 3)
print("Split Arrays:", split_array)
# c) Searching element
search_element = 5
result = np.where(joined_array == search_element)
print(f"Element {search_element} found at index:", result[0])
# d) Sorting
unsorted_array = np.array([3, 1, 5, 2, 4])
sorted_array = np.sort(unsorted_array)
print("Sorted Array:", sorted_array)
Output:
Joined Array: [1 2 3 4 5 6]
Split Arrays: [array([1, 2]), array([3, 4]), array([5, 6])]
Element 5 found at index: [4]
Sorted Array: [1 2 3 4 5]
Filtered Array (elements > 3): [4 5 6]
import pandas as pd
data = {
'USN': ['03SU23CC010', '03SU23CC068', '03SU23CC032', '03SU23DS019',
'03SU23DS022'],
'Name': ['AlRICK', 'SHREENIDHI', 'KALIDAS', 'SHARAN', 'VEEKSHITHA'],
'M1': [75, 82, 90, 65, 88],
'M2': [80, 72, 85, 70, 91],
'M3': [78, 84, 92, 68, 85]
}
df = pd.DataFrame(data)
df['Total'] = df['M1'] + df['M2'] + df['M3']
df['Average'] = df['Total'] / 3
print(df)
df.to_excel('student_marks.xlsx', index=False)
Output:
USN Name M1 M2 M3 Total Average
0 03SU23CC027 GOKUL 75 80 78 233 77.666667
1 03SU23CC068 SHREENIDHI 82 72 84 238 79.333333
2 03SU23CC032 KALIDAS 90 85 92 267 89.000000
3 03SU23DS019 SHARAN 65 70 68 203 67.666667
4 03SU23DS022 VEEKSHITHA 88 91 85 264 88.000000