0% found this document useful (0 votes)
2 views11 pages

IT Practical

The document contains a series of programming exercises that demonstrate basic operations with lists, tuples, sets, and dictionaries in Python. Each program includes a question, a sample answer with code, and the expected output. The exercises cover tasks such as adding elements to lists, swapping elements, finding maximum and minimum values, separating even and odd numbers, and manipulating dictionaries.

Uploaded by

omv9784
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)
2 views11 pages

IT Practical

The document contains a series of programming exercises that demonstrate basic operations with lists, tuples, sets, and dictionaries in Python. Each program includes a question, a sample answer with code, and the expected output. The exercises cover tasks such as adding elements to lists, swapping elements, finding maximum and minimum values, separating even and odd numbers, and manipulating dictionaries.

Uploaded by

omv9784
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/ 11

PROGRAM 1

Question 1 : Create a program to add 10


elements in a blank list one by one as the
user input.

Answer : a= [] for i in range(10):


x=int(input("enter elements for list "))
a.append(x)
print("list elements")
print(a)

Output :
list elements
[5, 3, 9, 1, 4, 7, 8, 6, 2, 0]
PROGRAM 2
Question 2 : Create a list having 5
elements and swap the first element of list
with last element.

Answer : a=[41,42,43,45,46]
print("list ",a)
a[0],a[-1]=a[-1],a[0]
print("Swap List ",a)

output :
Swap List [46, 42, 43, 45, 41]
PROGRAM 3
Question 3 : Create a program to find the
max and min value of list created in Q2.

Answer : a=[41,42,43,45,46]
print("maximum element in list ",max(a))
print("minimum element in list ",min(a))

Output :
maximum element in list 46
minimum element in list 41
PROGRAM 4
Question 4 : Create a program to separate even and
odd values from the given list into two different lists.
(12,3,4,8,6,53,55,86,9,51,63,98,87,95,67,98)

Answer :
a=[12,3,4,8,6,53,11,54,55,86,9,51,63,98,87] even=[]
odd=[]
for x in a:
if x%2==0:
even.append(x)
else:
odd.append(x)
print("Even List ",even)
print("Odd List ", odd)

Output :
Even List [12, 4, 8, 6, 54, 86, 98]
Odd List [3, 53, 11, 55, 9, 51, 63, 87]
PROGRAM 5
Question 5 : Create a tuple containing 8
element and find the sum and averages of
all its elements.

Answer : a=(12,3,4,8,6,53,11,54)
print("Sum of tuple elements ",sum(a))
print("Average of tuple elements
",sum(a)/len(a))

Output :
Sum of tuple elements 151
Average of tuple elements 18.875
PROGRAM 6

Question 6 : Create a tuple having odd


length and print the middle value in tuple.

Answer :
a=(12,3,4,8,6,53,11)
x=len(a)//2
print("middle element of tuple ",a[x])

Output :
middle element of tuple 8
PROGRAM 7
Question 7 : Create a program to check that
a particular element exist in a set or not .

Answer :a=(12,3,4,8,6,53,11)
x=6
if x in a:
print(x,"element found in tuple")
else:
print(x,"element not found in tuple")

Output :
6 element found in tuple

6 element not found in tuple


PROGRAM 8
Question 8 : Create a program to find the
unique value from the given list.
[10,45,10,56,45,89,75,85,10,45,56,14,15,45,
10,45,85,56]

Answer : a=[1, 2, 3, 3, 4, 4, 5, 5]
ulist=[]
for val in a:
if val not in ulist:
ulist.append(val)
print(ulist)

Output :
[1,2,3,4,5}
PROGRAM 9
Question 9 : Do the following operation on the given sets.
A = {10,20,30,40,50,60}
B ={5,15,20,25,30,35}
 Join both the sets to create a new one .
 Print the matching and non matching values in both sets.
 Add the elements 70,80 and 90 in set A and delete the
elements 5 and 15 from set B.
Answer : a=[10,20,30,40,50,60] b=[5,15,20,25,30,35]
c=a+b
print("join list ",c)
a.extend([70,80,90])
print("List a with new elements ",a) b.remove(5)
b.remove(15)
print("List b after deletion of elements ",b)
output :
Joined list: [10, 20, 30, 40, 50, 60, 5, 15, 20, 25, 30, 35]

List 'a' with new elements: [10, 20, 30, 40, 50, 60, 70, 80, 90]

List 'b' after deletion of elements: [20, 25, 30, 35]


PROGRAM 10
Country India Japan United Aruba Qatar
name states
Country 356 392 840 533 634
code
Question 10 : Create a dictionary named
‘Country’ for the given dataset.

Now perform the following operations on it.


 Add the country ‘Oman’ with country code ‘512’
 Print the store country name and code separately
in any collections.
 Remove united states and Qatar from the
dictionary.

Answer: country={}
country["india"]=356 country["japan"]=392
country["united states"]=840
country["Aruba"]=533 country["qatar"]=634
country["oman"]=512 key=country.keys()
val=country.values()
print ("keys of dictionary \n ",key) print("Values of
dictionary \n",val)
del country ["united states"]
del country["Oman"] print(country)

Output:
Keys of dictionary:
dict_keys(['India', 'Japan', 'united states', 'Aruba',
'qatar', 'Oman'])
Values of dictionary:
dict_values([356, 392, 840, 533, 634, 512])
Updated dictionary:
{'India': 356, 'Japan': 392, 'Aruba': 533, 'qatar': 634}

You might also like