Sei sulla pagina 1di 17

GUJARAT TECHNOLOGICAL UNIVERSITY

COMPUTER ENGINEERING
PYTHON PROGRAMMING
SUBJECT CODE: 2180711
B.E. 8th SEMESTER

Type of course: Department Elective III

Prerequisite: Programming Concepts

Rationale: Python is a modern language useful for writing compact codes specifically for programming in
the area of Server side Web development, Data Analytics, AI and scientific computing as well as
production tools and game programming. This course covers the basics and advanced Python programming
to harness its potential for modern computing requirements.

Teaching and Examination Scheme:

Teaching Scheme Credits Examination Marks Total


Theory Marks Practical Marks Marks
L T P C ESE PA (M) ESE (V) PA
(E) PA ALA ESE OEP (I)
3 0 2 5 70 20 10 20 10 20 150

Content:

Sr. No. Content Total % Weightage


Hrs
1 Introduction to Python 4 7%
 The basic elements of python
 Branching Programs
 Control Structures
 Strings and Input
 Iteration
2 Functions, Scoping and Abstraction 5 10%
 Functions and scoping
 Specifications
 Recursion
 Global variables
 Modules
 Files
 System Functions and Parameters
3 Structured Types, Mutability and Higher-Order Functions 4 8%
 Strings, Tuples, Lists and Dictionaries
 Lists and Mutability
 Functions as Objects
4 Testing, Debugging, Exceptions and Assertions 4 7%
 Types of testing – Black-box and Glass-box
 Debugging
 Handling Exceptions
 Assertions
5 Classes and Object-Oriented Programming 4 8%
 Abstract Data Types and Classes
 Inheritance
 Encapsulation and Information Hiding
6 Simple Algorithms and Data structures 5 10%
 Search Algorithms
 Sorting Algorithms
 Hash Tables
7 Advanced Topics I 10 20%
 Regular Expressions – REs and Python
 Plotting using PyLab
 Networking and Multithreaded Programming – Sockets,
Threads and Processes, Chat Application
8 Advance Topics II 12 30%
 Security – Encryption and Decryption , Classical Cyphers
 Graphics and GUI Programming – Drawing using Turtle, Tkinter
and Python, Other GUIs

Suggested Specification table with Marks (Theory):

Distribution of Theory Marks


R Level U Level A Level N Level E Level
10 18 18 18 06

Legends: R : Remembrance ; U = Understanding; A = Application; N = Analyze; E = Evaluation and


above Levels (Revised Bloom’s Taxonomy)

Reference Books:

1. John V Guttag. “Introduction to Computation and Programming Using Python”, Prentice Hall of
India
2. R. Nageswara Rao, “Core Python Programming”, dreamtech
3. Wesley J. Chun. “Core Python Programming - Second Edition”, Prentice Hall
4. Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser, “Data Structures and Algorithms
in Pyhon”, Wiley
5. Kenneth A. Lambert, “Fundamentals of Python – First Programs”, CENGAGE Publication
6. Luke Sneeringer, “Professional Python”, Wrox
7. “Hacking Secret Ciphers with Python”, Al Sweigart, URL-
https://inventwithpython.com/hacking/chapters

Course Outcome:

After learning the course, the student will be able:

 To develop proficiency in creating based applications using the Python Programming Language.
 To be able to understand the various data structures available in Python programming language and
apply them in solving computational problems.
 To be able to do testing and debugging of code written in Python.
 To be able to draw various kinds of plots using PyLab.
 To be able to do text filtering with regular expressions in Python
 To be able to create socket applications in Python
 To be able to create GUI applications in Python
Following guideline is to be kept in mind while framing the list:

 At least 25 programs are to be assigned.


 Programs should cover particular feature from syntactic concepts together with advanced topics and
definition based on real life problem.
 Practical list should cover entire syllabus.
 List of Experiments :
1. Develop programs to understand the control structures of python
2. Develop programs to learn different types of structures (list, dictionary, tuples) in python
3. Develop programs to learn concept of functions scoping, recursion and list mutability.
4. Develop programs to understand working of exception handling and assertions.
5. Develop programs for data structure algorithms using python – searching, sorting and hash
tables.
6. Develop programs to learn regular expressions using python.
7. Develop chat room application using multithreading.
8. Learn to plot different types of graphs using PyPlot.
9. Implement classical ciphers using python.
10. Draw graphics using Turtle.
11. Develop programs to learn GUI programming using Tkinter.

Major Equipments:

 Latest PCs with related software

List of Open Source Software/learning website:

 Turtle - https://docs.python.org/2/library/turtle.html
 PyLab - https://scipy.github.io/old-wiki/pages/PyLab

ACTIVE LEARNING ASSIGNMENTS: Preparation of power-point slides: which include videos,


animations, pictures, graphics for better understanding theory and practical work. The faculty will allocate
chapters/ parts of chapters to groups of students so that the entire syllabus can be covered. The power-point
slides should be put up on the web-site of the College/ Institute, along with the names of the students of the
group, the name of the faculty, Department and College on the first slide. The best three works should
submit to GTU.
Laxmi Institute of Technology, Sarigam
Approved by AICTE, New Delhi; Affiliated to Gujarat Technological University, Ahmedabad

Department of Computer Science & Engineering


BE IV SEM VIII
Academic Year 2017-18
Python Programming (2180711)
Tutorials

1. Write a python program to write a function that returns the result of sum of two numbers.
2. Write a python program to display prime number series within a given range using
function.
3. Write a python program to generate Fibonacci number series using function.
4. Write a python program to calculate the sine value of a given angle in degrees by
evaluating sine series.
5. Write a python program to calculate the cosine value of a given angle in degrees by
evaluating cosine series.
6. Write a python program to evaluate exponential series.
7. Write a python program to find factorial of a given number using recursive function.
8. Write a python program to solve the problem of tower of Hanoi using recursive function.
9. Write a python program to find maximum of two numbers using lambda function.
10. Write a python program to find products of elements of two different listusing lambda
function.
11. Write a python program to find factorial using lambda function.
12. Write a python program that uses the functions of employee module and calculate the
gross salaries and net salaries of an employee.

Subject I/C
Laxmi Institute of Technology, Sarigam
Approved by AICTE, New Delhi; Affiliated to Gujarat Technological University, Ahmedabad

Department of Computer Science & Engineering


BE IV SEM VIII
Academic Year 2018-19
Python Programming (2180711)
Assignment
1. What is lambda function in python? Explain with any one example.

2. Write a python program to search a specific value from a given list of values using binary
search method.

3. Write a Python program that counts the number of occurrences of the character in the given
string. Provide two implementations: recursive and iterative.

4. What is duck typing philosophy of python?

5. What is Method Resolution Order (MRO)? Explain the principles followed by MRO with
example.

6. Write a python program to arrange the characters of a given string 'welcome' in an


alphabetical order using insertion sort algorithm.

7. Explain the types of methods available in python with a suitable example of each method.

8. What are the differences between abstract class and interface? Write a python program in
which Maruti and Santro sub classes implement the abstract methods of the super class Car.

9. Create a class student with following member attributes: roll no, name, age and total marks.
Create suitable methods for reading and printing member variables. Write a python program
to overload ‘==’ operator to print the details of students having same marks.

10. Create following regular polygons (regular means all sides the same lengths, all angles the
same) using for loop in turtle
• An equilateral triangle
• A square
• A hexagon
• An octagon

11. What is list in Python? Demonstrate use of any three methods of list.

12. What is the use of islower() and isupper() method?

13. Write a Python program to check whether the given no is Armstrong or not using user
defined function.

14. How map can be used in Python program? Explain with a suitable example

15. Give the syntax and significance of string functions: title() and capitalize().

16. Write a Python program to implement the concept of inheritance.

17. Give the output of following Python code:


l=[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
print l

18. How filter can be used in Python program? Explain with a suitable example.

19. Create a class Employee with data members: name, department and salary. Create suitable
methods for reading and printing employee information.

20. Give the output of following Python code:


str1 = ‘This is Pyhton’
print "Slice of String : ", str1[1 : 4 : 1]
print "Slice of String : ", str1[0 : -1 : 2]

21. Is tuple mutable? Demonstrate any two methods of tuple.

22. Write a Python program to overload + operator.

23. Read a text file in Python and print no. of lines and no. of unique words.

24. List out and explain keywords used in exception handling.

25. What is dictionary in Python? Explain with an example.

26. Write a python program to retrieve name and date of birth (mm-dd-yyyy) of students from a
given file student.txt.

27. Write a python program to retrieve strings starting with m and having 5 characters.

28. Write a python program to append data to an existing file 'python.py'. Read data to be
appended from the user. Then display the contents of entire file.

29. Write a python program to know the current working directory and to print all contents of the
current directory. What changes we need to make in the program if we wish to display the
contents of only 'mysub' directory available in current directory?

Subject I/C
Laxmi Institute of Technology, Sarigam
Approved by AICTE, New Delhi; Affiliated to Gujarat Technological University, Ahmedabad

Department of Computer Science & Engineering


BE IV SEM VIII
Python Programming (2180711)
Question Bank
1. What are the differences between C and Python?

2. What are the differences between Java and Python?

3. What is lambda function in python? Explain with any one example.

4. Explain built-in datatypes of python.

5. Write a python program to search a specific value from a given list of values using binary
search method.

6. Write a Python program that counts the number of occurrences of the character in the given
string. Provide two implementations: recursive and iterative.

7. What is duck typing philosophy of python?

8. What is Method Resolution Order (MRO)? Explain the principles followed by MRO with
example.

9. Write a python program to arrange the characters of a given string 'welcome' in an


alphabetical order using insertion sort algorithm.

10. Explain the types of methods available in python with a suitable example of each method.

11. What are the differences between abstract class and interface? Write a python program in
which Maruti and Santro sub classes implement the abstract methods of the super class Car.

12. Create a class student with following member attributes: roll no, name, age and total marks.
Create suitable methods for reading and printing member variables. Write a python program
to overload ‘==’ operator to print the details of students having same marks.

13. Create following regular polygons (regular means all sides the same lengths, all angles the
same) using for loop in turtle
• An equilateral triangle
• A square
• A hexagon
• An octagon

14. How to comment specific line(s) in Python program?

15. Write a Python program to print Fibonacci series upto n terms.

16. What is list in Python? Demonstrate use of any three methods of list.

17. What is the use of islower() and isupper() method?

18. Give the syntax and significance of raw_input() and input() methods.
19. Write a Python program to check whether the given no is Armstrong or not using user
defined function.

20. How map can be used in Python program? Explain with a suitable example

21. Give the syntax and significance of string functions: title() and capitalize().

22. Write a Python program to implement the concept of inheritance.

23. Give the output of following Python code:


l=[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
print l

24. How filter can be used in Python program? Explain with a suitable example.

25. Create a class Employee with data members: name, department and salary. Create suitable
methods for reading and printing employee information.

26. Give the output of following Python code:


str1 = ‘This is Pyhton’
print "Slice of String : ", str1[1 : 4 : 1]
print "Slice of String : ", str1[0 : -1 : 2]

27. Is tuple mutable? Demonstrate any two methods of tuple.

28. Write a Python program to overload + operator.

29. Read a text file in Python and print no. of lines and no. of unique words.

30. List out keywords used in exception handling.

31. What is dictionary in Python? Explain with an example.

32. What is lambda function in Python? Explain with an example.

33. Explain steps to create widgets. Write Python program to display a label on clicking a push
button.

34. Explain the function which is used to retrieve the parts of URL.

35. Write Python GUI program to create two push buttons using Tkinter. Background color of a
frame should be changed when different buttons are clicked.

36. Briefly describe the methods of regular expression.

37. Write a Python program for TCP/IP chat application.

38. Write a Python GUI program to create three push buttons using Tkinter. The background
color of frame should be different when different buttons are clicked.

39. Explain the creation of different types of containers available in Tkinter? Elaborate the
explanation with suitable example.
40. Which are the different ways of creation of threads? Explain each with an example.

41. Write a python program to retrieve name and date of birth (mm-dd-yyyy) of students from a
given file student.txt.

42. Write a python program to retrieve strings starting with m and having 5 characters.

43. Write a python program to append data to an existing file 'python.py'. Read data to be
appended from the user. Then display the contents of entire file.

44. Write a python program to know the current working directory and to print all contents of the
current directory. What changes we need to make in the program if we wish to display the
contents of only 'mysub' directory available in current directory?

Subject I/C
Laxmi Institute of Technology, Sarigam
Approved by AICTE, New Delhi;
Affiliated to Gujarat Technological University, Ahmedabad
Academic Year 2018-19
Centre Code: 086 Examination : Mid Sem-I
Branch: CSE Semester: 8
Sub: Python Programming Date:28/01/2019 Marks: 20
Sub Code: 2180711 Time: 9 AM to 10 AM

Q.1 (a) How to comment specific line(s) in Python program? [2]


(b) Give the output of following Python code: [3]
str1 = ‘This is Pyhton’
print("Slice of String : ", str1[1 : 4 : 1])
print("Slice of String : ", str1[0 : -1 : 2])
(c) Write a python program to search a specific value from a list of [5]
numbers using sequential search method.
OR
(c) Write a python program to print Fibonacci series up to n term [5]
using recursive function where n is user input.

Q.2 (a) What is the difference between = = and is operator in Python? [2]
(b) Explain built-in datatypes of python. [3]
(c) Justify: “Functions are perfect objects.” [5]
OR
Q.2 (a) Explain in operator in Python with an example. [2]
(b) t = (1, 2, 3, (4, ), [ 5, 6] ) [3]
print(t[3])
t[4][0] = 7
print(t)
(c) Explain parameter passing method in python. [5]
Seat No.: ________ Enrolment No.___________

GUJARAT TECHNOLOGICAL UNIVERSITY


BE - SEMESTER–VIII (NEW) - EXAMINATION – SUMMER 2017
Subject Code: 2180711 Date: 02/05/2017
Subject Name: Python Programming(Departmental Elective - III)
Time: 10:30 AM to 01:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.

Q.1 (a) 1. Write a python program to know the current working directory and to 03
print all contents of the current directory. What changes we need to
make in the program if we wish to display the contents of only 'mysub'
directory available in current directory?
2. Write a python program to append data to an existing file 'python.py'. 04
Read data to be appended from the user. Then display the contents of
entire file.
(b) 1. Write a python program to retrieve strings starting with m and having 5 03
characters.
2. Write a python program to retrieve name and date of birth (mm-dd- 04
yyyy) of students from a given file student.txt.
Q.2 (a) 1. Explain the function that is used to retrieve the parts of URL. 02
2. Write a python program to create a TCP/IP client-server chat 05
application.
(b) What are the differences between C and Python? 07
OR
(b) 1. What is lambda function in python? Explain with any one example. 03
2. Explain built-in datatypes of python. 04
Q.3 (a) 1. Briefly describe the methods of regular expression. 02
2. Write a Python program that counts the number of occurrences of the 05
character in the given string. Provide two implementations: recursive
and iterative.
(b) Write a python program to search a specific value from a given list of values 07
using binary search method.
OR
Q.3 (a) 1. What is duck typing philosophy of python? 02
2. What is Method Resolution Order (MRO)? Explain the principles 05
followed by MRO with example.
(b) Write a python program to arrange the characters of a given string 'welcome' in 07
an alphabetical order using insertion sort algorithm.
Q.4 (a) Explain the types of methods available in python with a suitable example of 07
each method.
(b) Which are the different ways of creation of threads? Explain each with an 07
example.
OR
Q.4 (a) What are the differences between abstract class and interface? Write a python 07
program in which Maruti and Santro sub classes implement the abstract
methods of the super class Car.

1
(b) Create a class student with following member attributes: roll no, name, age and 07
total marks. Create suitable methods for reading and printing member variables.
Write a python program to overload ‘==’ operator to print the details of students
having same marks.
Q.5 (a) Explain the creation of different types of containers available in Tkinter? 07
Elaborate the explanation with suitable example.
(b) Create following regular polygons (regular means all sides the same lengths, all 07
angles the same) using for loop in turtle
 An equilateral triangle
 A square
 A hexagon
 An octagon
OR
Q.5 (a) Explain the major steps used to create widgets. Write a python program to 07
display a label upon clicking a push button.
(b) Write a Python GUI program to create three push buttons using Tkinter. The 07
background color of frame should be different when different buttons are
clicked.

*************

2
Seat No.: ________ Enrolment No.___________

GUJARAT TECHNOLOGICAL UNIVERSITY


BE - SEMESTER–VIII (NEW) EXAMINATION – WINTER 2017
Subject Code: 2180711 Date: 07/11/2017
Subject Name: Python Programming(Departmental Elective - III)
Time:02:30 PM TO 05:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.

Q.1 (a) How to comment specific line(s) in Python program? 03


(b) Write a Python program to print Fibonacci series upto n terms. 04
(c) What is list in Python? Demonstrate use of any three methods of list. 07
Q.2 (a) What is the use of islower() and isupper() method? 03
(b) Give the syntax and significance of raw_input() and input() methods. 04
(c) Write a Python program to check whether the given no is Armstrong or not 07
using user defined function.
OR
(c) Write a Python program to search a specific value from a given list of values 07
using binary search method.
Q.3 (a) How map can be used in Python program? Explain with a suitable example. 03
(b) Give the syntax and significance of string functions: title() and capitalize(). 04
(c) Write a Python program to implement the concept of inheritance. 07
OR
Q.3 (a) Give the output of following Python code: 03
l=[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
print l
(b) How filter can be used in Python program? Explain with a suitable example. 04
(c) Write a Python program for TCP/IP chat application. 07
Q.4 (a) Briefly describe the methods of regular expression. 03
(b) Give the output of following Python code: 04
str1 = ‘This is Pyhton’
print "Slice of String : ", str1[1 : 4 : 1]
print "Slice of String : ", str1[0 : -1 : 2]
(c) Write Python GUI program to create two push buttons using Tkinter. Background 07
color of a frame should be changed when different buttons are clicked.
OR
Q.4 (a) Is tuple mutable? Demonstrate any two methods of tuple. 03
(b) Create a class Employee with data members: name, department and salary. 04
Create suitable methods for reading and printing employee information.
(c) Write a Python program to overload + operator. 07
Q.5 (a) Explain the function which is used to retrieve the parts of URL. 03
(b) Read a text file in Python and print no. of lines and no. of unique words. 04
(c) Explain steps to create widgets. Write Python program to display a label on 07
clicking a push button.
OR
Q.5 (a) List out keywords used in exception handling. 03
(b) What is dictionary in Python? Explain with an example. 04
(c) What is lambda function in Python? Explain with an example. 07

*************

1
Seat No.: ________ Enrolment No.___________
GUJARAT TECHNOLOGICAL UNIVERSITY
BE - SEMESTER–VIII (NEW) - EXAMINATION – SUMMER 2018
Subject Code: 2180711 Date: 07/05/2018
Subject Name: Python Programming(Departmental Elective - III)
Time: 10:30 AM to 01:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.

Q.1 (a) Give syntax of the methods which can be used to take input from the user in 03
python program.
(b) Give the syntax and significance of string functions: title() and strip(). 04
(c) Write a Python program which will throw exception if the value entered by 07
user is less than zero.
Q.2 (a) How to comment specific line(s) in Python program? 03
(b) How append() and extend() are different with reference to list in Python? 04
(c) Write a Python program to find reverse of given number using user defined 07
function.
OR
(c) Write a Python program to search a specific value from a given list of values 07
using binary search method.
Q.3 (a) What is the difference between = = and is operator in Python? 03
(b) Give the output of following Python code: 04
myStr = ‘GTU is the best University’
print myStr [15 : : 1]
print myStr [-10 : -1 : 2]
(c) Write a Python program which will return the sum of the numbers in the array, 07
returning 0 for an empty array. Except the number 13 is very unlucky, so it
does not count and number that come immediately after 13 also do not count.
Example : [1, 2, 3, 4] = 10
[1, 2, 3, 4, 13] = 10
[13, 1, 2, 3, 13] = 5
OR
Q.3 (a) Briefly describe the methods of regular expression. 03
(b) Give the output of following Python code: 04
t = (1, 2, 3, (4, ), [ 5, 6] )
print t[ 3 ]
t[4][0] = 7
print t
(c) Write a Python program which takes a list and returns a list with the elements 07
"shifted left by one position" so [1, 2, 3] yields [2, 3, 1].
Example: [1, 2, 3] → [2, 3, 1]
[11, 12, 13] → [12, 13, 11]
Q.4 (a) Explain sort() with an example. 03
(b) How operator overloading can be implemented in Python? Give an example. 04
(c) Create a Python program to read a text file and do following: 07
1. Print no. of lines
2. Print no. of unique words
3. Store each word with its occurrence in dictionary

1
OR

Q.4 (a) How sorted() can be used with list in Python? Give an example. 03
(b) Differentiate between filter and map in Python using example. 04
(c) Write a Python program to implement the concept of echo server. 07
Q.5 (a) Explain in operator in Python with an example. 03
(b) Write a Python program to read a text file and do following: 04
1. Print no. of words
2. Print no. statements
(c) Write a Python program to create class GTU with attributes like class variable 07
cnt, instance variables x and y, instance methods get_value and print_value.

OR

Q.5 (a) Write a python program to implement any one classical cipher. 03
(b) Explain steps to create widgets. Write Python program to display a label on 04
clicking a push button.
(c) Write Python GUI program to create three push buttons using Tkinter. Background 07
color of a frame should be changed when different buttons are clicked.

*************

2
Seat No.: ________ Enrolment No.___________

GUJARAT TECHNOLOGICAL UNIVERSITY


BE - SEMESTER–VIII (NEW) EXAMINATION – WINTER 2018
Subject Code: 2180711 Date: 29/11/2018
Subject Name: Python Programming
Time: 02:30 PM TO 05:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.

MARKS
Q.1 (a) Explain lambda in Python with example 03
(b) Explain Method Overloading in Python 04
(c) Write a Python program to count words, characters and spaces 07
from text file
Q.2 (a) Explain List in Python 03
(b) Explain raw_input() and input() in Python 04
(c) Explain Tuples in Python with example 07
OR
(c) Explain Dictionary in Python with example 07
Q.3 (a) Explain title() and capitalize() methods 03
(b) Write a Python program to search a specific value from a given 04
list of values using linear search method
(c) Give Difference between abstract class and interface in Python 07
using an example
OR
Q.3 (a) Explain Exception Handling in Python 03
(b) Write a Python Program to multiply two matrices 04
(c) Develop chat application using Multithreading in Python 07
Q.4 (a) Explain namespaces in Python 03
(b) Write a Python program to remove the first occurrence of a 04
specified element from an array
(c) Explain encryption and decryption in Python using an example 07
OR
Q.4 (a) Write a Python program to generate the fibonacci series using 03
recursion
(b) Explain steps to create widgets in Python 04
(c) Write a Python program to match a string that contains only 07
upper and lowercase letters, numbers, and underscores using
Regular Expression
Q.5 (a) Explain Tkinter Widgets: Menu and Menubutton 03
(b) Explain map ,reduce and filter in Python 04
(c) Write a Python program to find the substrings within a string 07
using Regular Expression
OR
Q.5 (a) Explain Tkinter Widgets: button and radiobutton 03
(b) Explain pack()and place() method of Tkinter 04
(c) Draw Circle and Triangle shapes using Turtle and fill them with 07
red color

Potrebbero piacerti anche