rohidas

Hi I am Rohidas lande.I have teaching in C.D.jain college of commerce Shrirampur .I have Nine year in teaching Experience to teach various programming langauge,script languages,databases like Java,C,C++,php,python,html,css,javascript,mysql,oracle.

Python_assignment3

Savitribai Phule Pune University T. Y. B. B. A. (C. A.) Semester-V (CBCS 2019 Pattern) CA-506: Lab Book Credits-03 Assignment 3: Working with Tuples, Sets and Dictionaries
Sr.NoAssignment name
Set-A
1
Write a Python program to find maximum and the minimum value in a set.

Plz Click on Question to see Answer


n=int(input("Enter limit")) print("Enter n numbers") a=set() for i in range(0,n): num=input("Enter number") a.add(num) print("set values=",a) print("Minimum=",min(a)) print("Maximum=",max(a))


2
Write a Python program to add an item in a tuple. Plz Click on Question to see Answer

a=tuple() b=list() n=int(input("Enter limit")) for i in range(0,n): val=input("Enter values") b.append(val) a=tuple(b) print(a)


3
Write a Python program to convert a tuple to a string. Plz Click on Question to see Answer

a=('b','b','a','c','a') print("Display tuple",a) s1=" " for ch in a: s1=s1+ch print("String=",s1)


4
Write a Python program to create an intersection of sets. Plz Click on Question to see Answer

a=[10,20,30,40,50] print("List=",a) a.append(60) print("Push element in list=",a) val=a.pop() print("poped values=",val) print("After pop element in the list=",a)


5
Write a Python program to create a union of sets. Plz Click on Question to see Answer

a={10,20,30} b={40,20,50} c={10,20,60} d=a.union(b,c) print("Union Value=",d)


6
Write a Python script to check if a given key already exists in a dictionary. Plz Click on Question to see Answer

def checkKey(d,k): if k in d: print("Key is present") else: print("Key is not present") d={'a':10,'b':20,'c':30} k='b' checkKey(d,k)


7
Write a Python script to sort (ascending and descending) a dictionary by value. Plz Click on Question to see Answer

a={"15":"om","21":"sai","14":"ram","35":"sham"} b=sorted(a.values()) print("Values Ascending Order=",b) b=sorted(a.values(),reverse=True) print("Values Descending Order=",b)


Set-B
1
Write a Python program to create set difference and a symmetric difference.

Plz Click on Question to see Answer


a={10,20,30,40,50} b={10,60,70,40,50} print("Set Difference=",a.difference(b)) print("Symmetric Difference=",a.symmetric_difference(b))


2
Write a Python program to create a list of tuples with the first element as the number and second element as the square of the number. Plz Click on Question to see Answer

n=int(input("Enter limit")) a=[] for i in range(0,n): num=int(input("Enter number")) a.append((num,num*num)) print(a)


3
Write a Python program to unpack a tuple in several variables. Plz Click on Question to see Answer a=(10,20,30) print("Pack values=",a) x,y,z=a print("Value in X=",x) print("Value in Y=",y) print("Value in Z=",z)

s=input("Enter String:") w=input("Enter word:") a=[] count=0 a=s.split(" ") for i in range(0,len(a)): if(w==a[i]): count=count+1 print("count of the word is:") print(count)


4
Write a Python program to get the 4th element from frontand 4th element from last of a tuple. Plz Click on Question to see Answer

a=(11,22,33,44,55,66,77,88,99,35) print("Fourth Element=",a[3]) print("Fourth Element from Last=",a[-4])


5
Write a Python program to find the repeated items of a tuple. Plz Click on Question to see Answer

a=(10,20,30,40,10,20,20,30,50) d={} for val in a: if val in d: d[val]=d[val]+1 else: d[val]=1 for k in d: if d[k]!=1: print(k,"=",d[k])


6
Write a Python program to check whether an element exists Plz Click on Question to see Answer

a=(10,20,30,40,50) n=int(input("Enter No:")) if n in a: print("Element Exists") else: print("Element Not Exists")


7
Write a Python script to concatenate following dictionaries to create a new one. Sample Dictionary : dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} Expected Result:{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60} Plz Click on Question to see Answer

d1={"101":"om","102":"sai"} d2={"103":"ram","104":"sham"} d3={"105":"dada","106":"baba"} result=d1|d2|d3 print(result)


Set-C
1
Write a Python program to create a shallow copy of sets. Plz Click on Question to see Answer

a={10,20,30} b=a.copy() print("Original set=",a) print("Copy set=",b) a.add(55) print("After add Original set=",a) print("After add Copy set=",a.copy())


2
Write a Python program to combine two dictionary adding values for common keys. d1 = {'a': 100, 'b': 200, 'c':300} d2 = {'a': 300, 'b': 200, 'd':400} Sample output: Counter({'a':400,'b':400,'d': 400,'c': 300}) Plz Click on Question to see Answer

d1={"a":100,"b":200,"c":300} d2={"a":300,"b":200,"c":400} d3=d1.copy() for k in d2: if k in d3: d3[k]=d3[k]+d2[k] else: d3[k]=d2[k] print(d3)


Post a Comment

0 Comments