BAPATLA ENGINEERING COLLEGE:: BAPATLA
(Autonomous)
Python Programming
Code 20MEL500/SO00
III [Link]–VSemester
Practicals : 5 Hours/Week (2T+3P) Continuous Assessment : 30
Final Exam : 3 hours Final Exam Marks : 70
Pre-Requisite: None.
Course Objectives:
Understand and write code using the basics of Python, Statements, Expressions,
●
Conditional Executions, and Functions.
● Write code for Iteration, Strings, File I/O.
● Write code in creating, usage of Lists, Dictionaries, and Tuples.
Understand the concepts of Object Orientation, Databases and write code
●
implementing them.
Course Outcomes: Students will be able to:
CL-1 Understanding of scripting and the contributions of python language.
CL-2 Understanding of Python especially the object‐oriented concepts, using databases.
CL-3 Design and implement machine learning solutions to classification, regression.
Design and implement machine learning solutions to clustering problems and
CL-4
features of various data.
UNIT- I
Introduction: Overview, History of Python, Python Features, Environment Setup. Variables,
expressions, and statements: values and types, variables, names and keywords, statements,
operators and operands, expressions, order of operations, modulus operator, string operations,
asking the user for input, comments, choosing mnemonic variable names.
Conditional execution: Boolean expressions, logical operators, conditional execution,
Alternative execution, chained conditionals, nested conditionals, catching exceptions using try
and except, short-circuit evaluation of logical expressions.
Iteration: updating variables, the while statement, infinite loops and break, finishing
iterations with continue, definite loops using for, loop patterns.
UNIT- II
Functions: function calls, built-in functions, type conversion functions, random numbers,
math functions, adding new functions, definitions and uses, flow of execution, parameters
and arguments, fruitful functions and void functions.
Strings: string is a sequence, getting the length of a string using len, traversal through a string
with a loop, string slices, strings are immutable, looping and counting, the in operator, string
comparison, string methods, parsing strings, format operator.
Files I/O:persistence, opening files, text files and lines, reading files, searching through a file,
letting the user choose the file name, using try except and open, writing files.
UNIT- III
Lists: a list is a sequence, lists are mutable, traversing, operations, slices, methods, deleting
BAPATLA ENGINEERING COLLEGE:: BAPATLA
(Autonomous)
elements, functions, strings, parsing lines, objects and values, aliasing, arguments.
Dictionaries: dictionary as a set of counters, dictionaries and files, looping and dictionaries,
advanced text parsing.
Tuples: tuples are immutable, comparing tuples, tuple assignment, dictionaries and tuples,
multiple assignment with dictionaries, the most common words, using tuples as keys in
dictionaries, sequences.
UNIT-IV
Regular expressions: character matching in regular expressions, extracting data using regular
expressions, combining searching and extracting, escape character.
Object-Oriented Programming: Managing Larger Programs, Using Objects, starting with
Programs, Subdividing a Problem–Encapsulation, First Python Object, Classes as Types, Object
Lifecycle, Many Instances, Inheritance.
LIST OF EXPERIMENTS
1. Write a python program to check if the number is positive or negative or zero and
display an appropriate message.
2. Write a python program to take a string from the user and count the number of vowels
present and percentage of vowels in it.
3. Write a python program to find the most frequent words in a text file.
4. Write a Python Program to Find the Sum of First n Natural Numbers.
5. Write a python program to find the numbers which are divisible by 7 and multiple of 5
between 1500 and 2700
6. Write a Python Program to solve Quadratic Equations.
7. Create a program that asks the user for a number and then prints out a list of all the
divisors of that number.
8. Write a Python Program to Find HCF or GCD.
9. Write a Python Program to Find LCM.
10. Write a Python program to construct the following pattern, using a nested loop number.
11. Write a Python Program to sort the given words in Alphabetical Order.
12. Write a Python function to create the HTML string with tags around the word(s).
13. Write a Python program to reverse words in a string.
14. Write a Python program to strip a set of characters from a string.
15. Write a python function to find the maximum and minimum of a list of numbers.
16. Write a Python Program to Find the Square Root.
17. Write a Python Program to Convert Decimal to Binary Using Recursion.
18. Write a python recursive function to find the factorial of a given number.
19. Write a python program to find the longest word in each line of a given file.
20. Write a Python program to combine each line from the first file with the corresponding
line in the second file.
21. Write a Python program to read a random line from a file.
22. Write a Python program to split a list every Nth element.
Sample list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
Expected Output: [['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
23. Write a Python program to compute the similarity between two lists.
BAPATLA ENGINEERING COLLEGE:: BAPATLA
(Autonomous)
Sample data: ["red", "orange", "green", "blue", "white"], ["black", "yellow", "green",
"blue"]
Expected Output:
Color1-Color2: ['white', 'orange', 'red']
Color2-Color1: ['black', 'yellow']
24. Write a Python program to replace the last element in a list with another list.
Sample data: [1, 3, 5, 7, 9, 10], [2, 4, 6,8]
Expected Output: [1, 3, 5, 7, 9, 2, 4, 6, 8]
25. Write a Python program to find the repeated items of a tuple.
26. Write a Python program to convert a list with duplicates to a tuple without duplicates.
27. Write a Python program to reverse the elements of a tuple.
28. Write a Python program to replace the last value of tuples in a list.
Sample list: [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
Expected Output: [(10, 20, 100), (40, 50, 100), (70, 80, 100)]
29. Write a Python program to combine two dictionaries by 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})
30. Write a Python program to create and display all combinations of letters, selecting each
letter from a different key in a dictionary.
Sample data : {'1':['a','b'], '2':['c','d']} Expected Output:
ac
ad
bc
bd
31. Write a Python program to get the top three items in a shop.
Sample data: {'item1': 45.50, 'item2':35, 'item3': 41.30, 'item4':55, 'item5': 24}
Expected Output:
item4 55
item1 45.5
item3 41.3
32. Write a Python program to match both key values in two dictionaries.
Sample dictionary: {'key1': 1, 'key2': 3, 'key3': 2}, {'key1': 1, 'key2': 2}
Expected output: key1: 1 is present in both x and y
33. Write a Python class named Rectangle constructed by a length and width and a method
which will compute the area of a rectangle.
34. Write a Python class named Circle constructed by a radius and two methods which will
compute the area and the perimeter of a circle.
35. Write a Python program to create a Single Linked List using classes.
36. Write a Python program to create a FIFO queue using classes.
37. Predict the output of following Python programs and write the justification.
class X(object):
def __init (self,a):
[Link] = a
BAPATLA ENGINEERING COLLEGE:: BAPATLA
(Autonomous)
def doubleup(self):
[Link] *= 2
class Y(X):
def __init (self,a):
X. init (self,a)
def tripleup(self):
[Link] *= 3
obj = Y(4)
print([Link])
[Link]()
print([Link])
[Link]()
print([Link])
38. Predict the output of following Python programs and write the justification.
# Base or Super class
class Person(object):
def __init (self, name):
[Link] = name
def getName(self):
return [Link]
def isEmployee(self):
return False
# Inherited or Subclass (Note Person in bracket)
class Employee(Person):
def __init (self, name, eid):
„„„In Python 3.0+, “super().__init__(name)”also works‟‟‟
super(Employee, self).__init__(name)
[Link] = eid
def isEmployee(self):
return True
def getID(self):
return [Link]
# Driver code
emp = Employee("Geek1", "E101")
print([Link](), [Link](), [Link]())
Text Books : 1. A Python Book: Beginning Python, Advanced Python, and Python
Exercises, Dave Kuhlman, Open Source MIT License.
2. Python for Data Analysis, Wes McKinney, O‟ Reilly.
References : 1. Python Data Science Handbook-Essential Tools for Working with
2. Data Science from Scratch, JoelGrus, O‟Reilly.