Python File
Python File
PROGRAM 1
OBJECTIVE: To write a Python Program to print HELLO INDIA.
CODE: print(“HELLO INDIA”)
PROGRAM 2
OBJECTIVE: To write a Python program to Find the Division of Student.
CODE: def calculate_division(marks):
total_marks = sum(marks)
else:
return "Fail"
division = calculate_division(marks)
print("Division:", division)
1 SPARSH GOYAL
PYTHON
PROGRAM 3
2 SPARSH GOYAL
PYTHON
PROGRAM 4
3 SPARSH GOYAL
PYTHON
PROGRAM 5
return a + b
return a - b
greet(name)
4 SPARSH GOYAL
PYTHON
PROGRAM 6
OBJECTIVE: To write a Python Program to Implement List.
CODE: # Define an empty list
my_list = []
# Append elements to the list
my_list.append(10)
my_list.append(20)
my_list.append(30)
my_list.append(40)
my_list.append(50)
# Print the list
print("Original List:", my_list)
# Access elements by index
print("Element at index 0:", my_list[0])
print("Element at index 3:", my_list[3])
# Modify an element
my_list[1] = 25
print("Modified List:", my_list)
# Remove an element
removed_element = my_list.pop(2)
print("List after removing element at index 2:", my_list)
print("Removed element:", removed_element)
# Insert an element at a specific index
my_list.insert(2, 35)
print("List after inserting 35 at index 2:", my_list)
# Check if an element exists in the list
if 30 in my_list:
print("30 is present in the list")
else:
print("30 is not present in the list")
# Print the length of the list
print("Length of the list:", len(my_list))
5 SPARSH GOYAL
PYTHON
6 SPARSH GOYAL
PYTHON
PROGRAM 7
7 SPARSH GOYAL
PYTHON
PROGRAM 8
8 SPARSH GOYAL
PYTHON
PROGRAM 9
OBJECTIVE: To Write a Python Program to Implement MERGE SORT.
CODE: def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
left_half = arr[:mid]
right_half = arr[mid:]
merge_sort(left_half)
merge_sort(right_half)
i=j=k=0
arr[k] = left_half[i]
i += 1
else:
arr[k] = right_half[j]
j += 1
k += 1
arr[k] = left_half[i]
i += 1
k += 1
arr[k] = right_half[j]
j += 1
k += 1
# Example usage:
merge_sort(my_list)
9 SPARSH GOYAL
PYTHON
PROGRAM 10
10 SPARSH GOYAL