IT Practical
IT Practical
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
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
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]
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}