0% found this document useful (0 votes)
8 views7 pages

Chapter 7solution

The document contains a worksheet for XI Computer Science with programming exercises focused on lists in Python. It includes various tasks such as creating lists of positive and negative integers, finding the largest elements, calculating the median, removing duplicates, and performing operations like insertion and deletion. Each question is accompanied by a sample code solution demonstrating the required functionality.

Uploaded by

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

Chapter 7solution

The document contains a worksheet for XI Computer Science with programming exercises focused on lists in Python. It includes various tasks such as creating lists of positive and negative integers, finding the largest elements, calculating the median, removing duplicates, and performing operations like insertion and deletion. Each question is accompanied by a sample code solution demonstrating the required functionality.

Uploaded by

HARSHIT .S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Date: 13.09.

2024 XI - Computer Science Marks : 20


Worksheet – 10(Lists in Python- Programs)
Q.NO Unsolved Questions Solutions

13. Write a program to read a list of n integers(positive as well as negative).Create two


new lists, one having all positive numbers and the other having all having negative
numbers from the given list. Print all the three lists
List=[]

Pos=[]

Neg=[]

n=int(input("Enter how many element :"))

print("Enter", n ,"elements one by one :")

for i in range(n):

e=int(input())

List.append(e)

if e>0:

Pos.append(e)

else:

Neg.append(e)

print("Original List :",List)

print("Positive elements List :",Pos)

print("Negative elements List :",Neg)

14. Write a program to find the largest and second largest elements in a given list of
elements.
List=[]

n=int(input("Enter how many element :"))

print("Enter", n ,"elements one by one :")

for i in range(n):
e=int(input())

List.append(e)

print("Original List :",List)

List.sort(reverse=True)

print("Largest Element in List :",List[0])

print("Second Largest Element in List :",List[1])

15. Write a program to read a list of n integers and find their median. Note: The median
value of a list of values is the middle one when they are arranged in order. If there are
two middle values, then take their average.
List=[]

n=int(input("Enter how many element :"))

print("Enter", n ,"elements one by one :")

for i in range(n):

e=int(input())

List.append(e)

print("Original List :",List)

List.sort(reverse=True)

print("Sorted List :",List)

m=n//2

if n%2==0:

median=(List[m]+List[m-1])/2

else:

median=List[m]

print("Median value in the List :",median)

18. Write a program to read a list of elements. Modify this list so that it does not contain

any duplicate items.(i.e.) all elements occurring multiple times in the list should appear
only once
List=[]
newlist=[]

n=int(input("How many elements..."))

print("Enter ",n," Elements one by one")

for i in range(n):

e=int(input())

List.append(e)

print("Original List : ",List)

for i in List:

if i not in newlist:

newlist.append(i)

print("List after removed duplicate elements :",newlist)

19. Write a program to create a list of elements. Input an element from the user that has
to be inserted in the list. Also, input the position at which it is to be inserted.
List=[10,20,30,40,50]

ele=int(input("Enter the element to be insert :"))

pos=int(input("Enter the position :"))

List.insert(pos-1,ele)

print("List after insert an element : ",List)

20. Write a program to read elements of a list and do the following

(i) The program should ask for the position of the element to be deleted from the list
and delete the desired element from the list.

(ii)The program should ask for the value to be deleted from the list and delete the
desired value from the list.
List=[]

n=int(input("Enter the no of element to be insert :"))

print("Enter ",n," elements one by one")

for i in range(n):

e=int(input())

List.append(e)
print("List elements are : ",List)

pos=int(input("Enter the position of the element to be


delete :"))

List.pop(pos-1)

print("List elements after deleted :",List)

val=int(input("Enter the value to be delete :"))

List.remove(val)

print("List elements after deleted :",List)

21. #Program to find sum of odd numbers in a list array

def add(List):

s=0

for i in List:

if i%2 !=0:

s+=i

return s

S=[1,4,7,8,3,7,8]

print("Sum of odd values in a List :",add(S))

22. #Program to calculate mean of given list of numbers using user defined function
def mean(List):

s=0

for i in List:

s+=i

return (s/len(List))

S=[1,4,7,8,3,7,8]

print("Mean value in a List :",mean(S))

23. #Program to delete all duplicate items in a list


List=[]

newlist=[]
n=int(input("How many elements..."))

print("Enter ",n," Elements one by one")

for i in range(n):

e=int(input())

List.append(e)

print("Original List : ",List)

for i in List:

if i not in newlist:

newlist.append(i)

print("List after removed duplicate elements :",newlist)

24. #Program to calculate minimum number of elements in a list


List=[]

n=int(input("How many elements..."))

print("Enter ",n," Elements one by one")

for i in range(n):

e=int(input())

List.append(e)

print("Original List : ",List)

print("Minimum element in the List :",min(List))

25. #Program to calculate and display total marks and percentage of a student
marks=[]

print("Enter your 5 subjects mark one by one")

tot=0

avg=0

for i in range(5):

m=int(input())

marks.append(m)
tot+=marks[i]

avg=tot/5

print("Students mark :",marks)

print("Total :",tot)

print("Average :",avg)

26. #Program to multiply odd index of elements present in a list containing numbers and
strings by 2
List=[1,'A',2,'B','C',4,5,'D','E',6,7,8,'F','G']

for i in range(1,len(List),2):

print(List[i]*2)

27. #Program to count frequency of an element in a given list


List=[1,'A',2,'B','C',4,1,'D','E',6,7,2,'F','G']

for i in range(len(List)):

a=List.count(List[i])

print("Frequency of ",List[i]," = ",a)

28. #Program to shift elements circularly right.


List=[]

n=int(input("How many elements to be add now :"))

print("Enter ",n," Elements one by one")

for i in range(n):

a=int(input())

List.append(a)

print("List element are : ",List)

T=List[n-1]

for i in range(len(List)-1, 0 ,-1):

List[i]=List[i-1]

List[0]=T

print("After Shifting the elements are : ",List)


29. #Program to swap content with next value divisible by 5
List=[3,25,13,6,35,8,14,45]

for i in range(len(List)):

if List[i]%5==0:

List[i],List[i-1]=List[i-1],List[i]

print("List after swapping : ",List)

30. The record of a student(Name,RollNo,Marks in five subjects,percentage of marks) is


stored in the following list:

stRecord=['Raman','A-36',[56,98,99,72,69],78.8]

Write python statements to retrieve the following information from the list strecord.

i) Percentage of student
stRecord[3]

ii)Marks in fifth subject


stRecord[2][4]

iii)Maximum marks of the student

max(stRecord[2])

iv)Roll No. of the student

stRecord[1]

v)Change the name of the student from 'Raman' to 'Raghav'

stRecord[0]='Raghav'

You might also like