0% found this document useful (0 votes)
6 views3 pages

List Program

The document contains multiple Python programs demonstrating various functionalities, including adding elements of two lists, finding the maximum of user-defined student marks, and implementing a menu-driven program for list operations. It also includes a program to create a dictionary for employee names and salaries, and a program to develop a 3x3 matrix with values from 11 to 20 using NumPy. Each program is structured with user input and output to illustrate its purpose.

Uploaded by

aatifshaikh0291
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

List Program

The document contains multiple Python programs demonstrating various functionalities, including adding elements of two lists, finding the maximum of user-defined student marks, and implementing a menu-driven program for list operations. It also includes a program to create a dictionary for employee names and salaries, and a program to develop a 3x3 matrix with values from 11 to 20 using NumPy. Each program is structured with user input and output to illustrate its purpose.

Uploaded by

aatifshaikh0291
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Develop a Python Program Write a program to add the elements of two list.

List1=[1,2,3,4]
List2=[4,5,2,3]
new_list=[]
length=len(List1)
i=0
for i in range(length):
new_list.append(List1[i]+List2[i])
print(new_list)

2. Develop a Python Program to Create a list of students' marks with user-defined values
and find the maximum.
n=int(input("enter the number of students"))
#creating empty list
list_marks=[]
#accepting marks and appending marks into the list
for i in range(n):
m=int(input(f"enter mark of student {i}:"))
list_marks.append(m)
maximum_marks=max(list_marks)
print("maximum mark is: ", maximum_marks)

3. Menu program on List


my_list = [22, 4, 16, 38, 13]

while True:
print("\nMenu:")
print("1. Append an element")
print("2. Insert an element")
print("3. Append a list to the given list")
print("4. Modify an existing element")
print("5. Delete an existing element from its position")
print("6. Delete an existing element with a given value")
print("7. Sort the list in ascending order")
print("8. Sort the list in descending order")
print("9. Display the list")
print("0. Exit")

choice = input("Enter your choice: ")

if choice == "1":
element = input("Enter element to append: ")
my_list.append(element)
print("Element appended.",my_list)

elif choice == "2":


element = input("Enter element to insert: ")
pos = int(input("Enter position to insert at (0-based index): "))
if 0 <= pos <= len(my_list):
my_list.insert(pos, element)
print("Element inserted.",my_list)
else:
print("Invalid position.")

elif choice == "3":


new_list = input("Enter elements of list separated by space: ").split()
my_list.extend(new_list)
print("List appended.")

elif choice == "4":


pos = int(input("Enter position of element to modify (0-based index): "))
if 0 <= pos < len(my_list):
new_val = input("Enter new value: ")
my_list[pos] = new_val
print("Element modified.")
else:
print("Invalid position.")

elif choice == "5":


pos = int(input("Enter position of element to delete (0-based index): "))
if 0 <= pos < len(my_list):
removed = my_list.pop(pos)
print("Element '{removed}' deleted.",my_list)
else:
print("Invalid position.")

elif choice == "6":


val = input("Enter value to delete: ")
if val in my_list:
my_list.remove(val)
print("Element '{val}' deleted.",my_list)
else:
print("Value not found in list.")

elif choice == "7":


my_list.sort()
print("List sorted in ascending order.",my_list)

elif choice == "8":


my_list.sort(reverse=True)
print("List sorted in descending order.",my_list)

elif choice == "9":


print("Current list:", my_list)

elif choice == "0":


print("Exiting program.")
break

else:
print("Invalid choice. Try again.")
4. Program to create a dictionary which stores names of employees and their salary
num = int(input("Enter the number of employees whose data to be stored: "))
count = 1
employee = dict() #create an empty dictionary
for count in range (n):
name = input("Enter the name of the Employee: ")
salary = int(input("Enter the salary: "))
employee[name] = salary
print("\n\nEMPLOYEE_NAME\tSALARY")
for k in employee:
print(k,'\t\t',employee[k])

5. Write a program to develop a matrix of 3x3 with values from 11 to 20.


import numpy as np
# Create an array with values from 11 to 19 (3x3 = 9 elements)
matrix = [Link](11, 20).reshape(3, 3)
print("3x3 Matrix with values from 11 to 19:")
print(matrix)

You might also like