You are on page 1of 5

<20CE158> <Pratham Patel>

Faculty of Technology and Engineering


U & P U. Patel Department of Computer Engineering
Date: 01 / 12 / 2021

Practical List
Academic Year : 2021-22 Semester : 4
Course code : CE259 Course name : Programming in Python

Note: Practical List is for Students. We need to cover concept require to implement respective
practical

Sr. Aim
No.
1. Installation & Configuration of Python(3.6 or 3.7) and Virtual Environment. Along with
its all major editors, IDLE, Pycharm, Anaconda, Jupyter, Interpreter etc.
Note: Do not install the latest version of python due to some backward
compatibility issues.

Please take screenshots of each point mentioned in the assignment and upload .pdf
file.

2. Dictionary
a. Write a Python script to check whether a given key already exists in a
dictionary.
b. Write a Python script to merge two Python dictionaries.
c. Write a Python program to sum all the items in a dictionary.
d. Write a Python script to add a key to a dictionary.
Sample Dictionary : {0: 10, 1: 20}
Expected Result : {0: 10, 1: 20, 2: 30}
e. Write a Python script to concatenate the 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}
Tuple
a. Write a Python program to create a tuple with different data types.
b. Write a Python program to create a tuple with numbers and print one item.
c. Write a Python program to add an item in a tuple.
Page 1 of 5
<20CE158> <Pratham Patel>
d. Write a Python program to convert a tuple to a string.
e. Write a Python program to find the length of a tuple.
Set
a. Write a Python program to add member(s) in a set and clear a set
b. Write a Python program to remove an item from a set if it is present in the
set.
c. Write a Python program to create an intersection, Union, difference of sets.
d. Write a Python program to find maximum and the minimum value in a set.
4. Write a Python program to find the most common elements and their counts
from list, tuple, dictionary.

Code :

##20CE158 Pratham Patel


##Github Repository Link
##https://github.com/pratham142/Assigment-PIP
##Dictionaries
##(a)
d1 = {0:10,1:20,2:30,3:40}
d2 = {4:50,5:60}
try:
n = int(input())
except ValueError:
print("Enter Integer Value")
try:
if n in d1:
print("Key already exists")
else:
print("Key doesn't exist")
except NameError:
pass
##(b)
d3 = {**d1, **d2}
##(c)
s=0
for i in range(len(d3)):
s += d3[i]
print(s)
##(d)
q = int(input("Enter key: "))
p = int(input("Enter value: "))
d3[q] = p
##(e)
d1.update(d2)
d1.update(d3)
print(d1)
##Tuple
##(a)
t1 = ("Charusat University",1,12.25)
print(t1)
##(b)
t2 = (1,2,3,4,5)
Page 2 of 5
<20CE158> <Pratham Patel>
print(t2[4])
##(c)
k = int(input("Enter a number: "))
l = list(t2)
l.append(k)
t2 = tuple(l)
print(t2)
##(d)
s = str(t1)
print(type(s))
##(e)
print(len(t1))
##Set
##(a)
s1 = {1,2,3,4,5}
a = int(input("Enter a number: "))
s1.add(a)
print(s1)
s1.clear()
print(s1)
##(b)
s1 = {1,2,3,4,5}
b = int(input("Enter a number: "))
if b in s1:
s1.remove(b)
else:
pass
print(s1)
##(c)
s2 = {3,4,5,6,7}
print(s1.intersection(s2))
print(s1.union(s2))
print(s1 - s2)
print(s2 - s1)
##(d)
print(max(s1), min(s1))
##(e)
list = [1,2,2,2,4,4,4,4,5]
tuple = (3,3,4,4,4,5,5,5,5)
dict = {1:5,2:5,3:6,4:7,5:7,6:7,7:7}
dict1 = {}
for i in range(0,len(list)):
print(list.count(list[i]))
for i in range(0,len(tuple)):
print(tuple.count(tuple[i]))
for key,values in dict.items():
if values not in dict1:
dict1[values] = [key]
else:
dict1[values].append(key)
print(str(dict1))

Page 3 of 5
<20CE158> <Pratham Patel>

Page 4 of 5
<20CE158> <Pratham Patel>

3.
4.
5.
6.
7.
8.
9.
10.

Page 5 of 5

You might also like