Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
Subject Title Python Application Programming
Subject Code 18EC646 IA Marks 40
Number of Lecture Hrs / Week 03 L Exam Marks 60
Total Number of Lecture Hrs 40 Exam Hours 03
FACULTY DETAILS:
Name: Prof. [Link] Designation: Assistant Professor Experience: 9 yrs
No. of times course taught:01 Specialization: VLSI Design &Embedded Systems
1.0 Prerequisite Subjects:
Sl. No Branch Semester Subject
01 ECE I/II Programming in C
2.0 Course Objectives
1. This course will enable students to Learn syntax and semantics and create Functions in Python.
2. This course will enable students to Handle Strings and Files in Python.
3. This course will enable students to Understands Lists, Dictionaries and regular expression in python.
4. This course will enable students to Implement object oriented programming concepts in Python
5. This course will enable students to Build web services, network and database program in Python.
3.0 Course Outcomes
Having successfully completed this course, the student will be able to
RBT
Course Outcome POs
Level
Examine Python syntax and semantics and be fluent in the use of PO1,PO2,PO3,PO4,PO5,
CO1 L3
python flow control and functions. PO6,PO8, PO10,PO11,PO12
CO2 Demonstrate proficiency in handling strings and File systems. L3 PO1,PO2,PO3,PO4,PO5,
PO6,PO8, PO10,PO11,PO12
Create run and manipulate Python programs using core data
CO3 structures like Lists, Dictionaries and use regular expressions. L3 PO1,PO2,PO3,PO4,PO5,
PO6,PO8, PO10,PO11,PO12
Interpret the concepts of object oriented programming as used in python. PO1,PO2,PO3,PO4,PO5,
CO4 L3
PO6,PO8, PO10,PO11,PO12
Implement exemplary applications related to Network programming ,web services PO1,PO2,PO3,PO4,PO5,
CO5 L3
and database in python. PO6,PO8, PO10,PO11,PO12
Total Hours of instruction 40
1
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
4.0 Course Content
Course Content:
Module-1 RBT
Level
Why should you learn to write programs, Variables, Expressions and statements, Conditional Execution,
Functions L1, L2, L3
08 Hours
Module-2
Iteration , Strings , Files
L1, L2, L3
08Hours
Module-3
Lists, Dictionaries, Tuples, Regular Expressions
L1, L2, L3
08Hours
Module-4
Classes and Objects, Classes and Functions, Classes and Methods
L1, L2, L3
08Hours
Module-5
Networked programs, Using Web services, Using Databases and SQL
L1, L2, L3
08Hours
5.0 Relevance to future subjects
Sl Semester Subject Topics
No
01 VIII Project work Embedded system
6.0 Relevance to Real World
SL. No Real World Mapping
01 To design the most of the embedded systems
7.0 Gap Analysis and Mitigation
Sl. No Delivery Type Details
01 Tutorial Python institute organization
02 NPTEL Course: The joy of Python computing using Python
8.0 Books Used and Recommended to Students
Text Books
1. Charles R. Severance, Python for Everybody: Exploring Data Using Python 3, 1 Edition, Create Space
Independent Publishing Platform, 2016 (Chapters 1 – 13, 15).
2. Allen B. Downey, “Think Python: How to Think Like a Computer Scientist, 2ndEdition, Green Tea Press, 2015
(Chapters 15,16,17)
Reference Books
1. Mark Lutz, “Programming Python”, 4th Edition, O’Reilly Media, [Link]-13: 978-9350232873. 2. Wesley J
Chun, “Core Python Applications Programming”, 3rd Edition, Pearson Education India, 2015. ISBN-13: 978-
9332555365. 3. Reema Thareja, “Python Programming using problem solving approach”, Oxford university press,
2
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
2017
Additional Study material & e-Books
1. NPTEL notes and Videos
2. VTU online notes.
Relevant Websites (Reputed Universities and Others) for
9.0
Notes/Animation/Videos Recommended
Website and Internet Contents References
1) [Link]
2) [Link]
10.0 Magazines/Journals Used and Recommended to Students
Sl. Magazines/Journals website
No
1 Python-Complete manual [Link]
CompleteManual/Technology/
2 Python-News and Articles [Link]
11.0 Examination Note
Internal Assessment: 40 Marks
Three IA will be conducted and average of best of two will be accounted.
Scheme of Evaluation for Internal Assessment (30 Marks)
(a) Internal Assessment test in the same pattern of the main examination.
(b) Assignment- 10Marks
SCHEME OF EXAMINATION:
Question paper pattern:
The question paper will have ten questions.
Each full question consists of 20marks.
There will be 2 full questions (with a maximum of four sub questions) from each module.
Each full question will have sub questions covering all the topics under a module
The students will have to answer 5 full questions, selecting one full question from each module.
3
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
12.0 Course Delivery Plan
Course Delivery Plan:
LECTURE % OF
MODULE CONTENT OF LECTURE
NO. PORTION
1 Introduction to C programming
2 Why should you learn to write programs
3 Variables
4 Expressions
1 20
5 statements
6 Conditional Execution
7 Functions
8 Related Programs
9 Iteration
10 Examples on Iterations
11 Iteration implementation programs
12 Strings
2 40
13 Examples on Strings
14 Strings implementation programs
15 Files
16 Files Example & implementation programs
17 Lists
18 Lists Example
19 Dictionaries
3 20 Dictionaries Example programs
Tuples 60
21
22 Tuples Example programs
23 Regular Expressions
24 Regular Expressions Example programs
25 Classes and Objects
26 Classes and Objects Example programs
27 Classes and Functions
28 Classes and Functions Example programs
80
4
29 Classes and Methods
30 Classes and Methods Example programs
31 Programs
32 Applications problems
4
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
33 Networked programs
34 Networked programs Example programs
35 Using Web services
36 Using Web services Example programs
5 100
37 Using Databases
38 Using Databases Example programs
39 Using SQL
40 Using SQL Example programs
13.0 QUESTION BANK
Module I
1: What is the function of the secondary memory in a com- puter?
a) Execute all of the computation and logic of the program
b) Retrieve web pages over the Internet
c) Store information for the long term, even beyond a power cycle
d) Take input from the user
2: What is a program?
3: What is the difference between a compiler and an inter- preter?
4: Which of the following contains “machine code”?
a) The Python interpreter
b) The keyboard
c) Python source file
d) A word processing document
5: What is wrong with the following code:
>>> primt 'Hello world!'
File "<stdin>", line 1
primt 'Hello world!'
^
SyntaxError: invalid syntax
>>>
6: Where in the computer is a variable such as “x” stored after the following Python line finishes?
x = 123
a) Central processing unit
b) Main Memory
c) Secondary Memory
d) Input Devices
e) Output Devices
7: What will the following program print out:
x = 43
5
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
x=x+1
print(x)
a) 43
b) 44
c) x + 1
d) Error because x = x + 1 is not possible mathematically
8: Explain each of the following using an example of a hu- man capability: (1) Central processing unit, (2) Main Memory,
(3) Secondary Memory, (4) Input Device, and (5) Output Device. For ex- ample, “What is the human equivalent to a
Central Processing Unit”?
9: How do you fix a “Syntax Error”?
10: Write a program that uses input to prompt a user for their name and then welcomes them.
Enter your name: Chuck
Hello Chuck
11: Write a program to prompt the user for hours and rate per hour to compute gross pay.
Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25
We won’t worry about making sure our pay has exactly two digits after the decimal
place for now. If you want, you can play with the built-in Python round function
to properly round the resulting pay to two decimal places.
12: Assume that we execute the following assignment state- ments:
width = 17
height = 12.0
For each of the following expressions, write the value of the expression and the
type (of the value of the expression).
1. width//2
2. width/2.0
3. height/3
4. 1 + 2 * 5
Use the Python interpreter to check your answers.
13: Write a program which prompts the user for a Celsius tem- perature, convert the temperature to Fahrenheit, and
print out the converted temperature.
14: Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours.
Enter Hours: 45
Enter Rate: 10
Pay: 475.0
15: Rewrite your pay program using try and except so that your program handles non-numeric input gracefully by
printing a message and exiting the program. The following shows two executions of the program:
Enter Hours: 20
Enter Rate: nine
Error, please enter numeric input
Enter Hours: forty
Error, please enter numeric input
16: Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error message. If the
score is between 0.0 and 1.0, print a grade using the following table:
6
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
Score Grade
>= 0.9 A
>= 0.8 B
>= 0.7 C
>= 0.6 D
< 0.6 F
Enter score: 0.95
A
Enter score: perfect
Bad score
Enter score: 10.0
Bad score
Enter score: 0.75
C
Enter score: 0.5
F
Run the program repeatedly as shown above to test the various different values for
input.
17: What is the purpose of the “def” keyword in Python?
a) It is slang that means “the following code is really cool”
b) It indicates the start of a function
c) It indicates that the following indented section of code is to be stored for later
d) b and c are both true
e) None of the above
18: What will the following Python program print out?
def fred():
print("Zap")
def jane():
print("ABC")
jane()
fred()
jane()
a) Zap ABC jane fred jane
b) Zap ABC Zap
c) ABC Zap jane
d) ABC Zap ABC
e) Zap Zap Zap
19: Rewrite your pay computation with time-and-a-half for over- time and create a function called computepay which
takes two parameters (hours and rate).
Enter Hours: 45
Enter Rate: 10
Pay: 475.0
20: Rewrite the grade program from the previous chapter using a function called computegrade that takes a score as its
parameter and returns a grade as a string.
Score Grade
>= 0.9 A
>= 0.8 B
>= 0.7 C
>= 0.6 D
< 0.6 F
7
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
Enter score: 0.95
A
Enter score: perfect
Bad score
Enter score: 10.0
Bad score
Enter score: 0.75
C
Enter score: 0.5
F
Run the program repeatedly to test the various different values for input.
Module II
1: Write a program which repeatedly reads numbers until the user enters “done”. Once “done” is entered, print out the
total, count, and average of the numbers. If the user enters anything other than a number, detect their mistake using try
and except and print an error message and skip to the next number.
Enter a number: 4
Enter a number: 5
Enter a number: bad data
Invalid input
Enter a number: 7
Enter a number: done
16 3 5.333333333333333
2: Write another program that prompts for a list of numbers as above and at the end prints out both the maximum and
minimum of the numbers instead of the average.
3: Take the following Python code that stores a string: str = 'X-DSPAM-Confidence:0.8475' Use find and string slicing to
extract the portion of the string after the colon character and then use the float function to convert the extracted string
into a floating point number.
4: Read the documentation of the string methods at [Link] You
might want to experiment with some of them to make sure you understand how they work. strip and replace are
particularly useful. The documentation uses a syntax that might be confusing. For example, in find(sub[, start[, end]]), the
brackets indicate optional arguments. So sub is required, but start is optional, and if you include start, then end is
optional.
5: Write a program to read through a file and print the contents of the file (line by line) all in upper case. Executing the
program will look as follows:
python [Link]
Enter a file name: [Link]
FROM [Link]@[Link] SAT JAN 5 09:14:16 2008
RETURN-PATH: <POSTMASTER@[Link]>
RECEIVED: FROM MURDER ([Link] [[Link]])
BY [Link] (CYRUS V2.3.8) WITH LMTPA;
SAT, 05 JAN 2008 09:14:16 -0500
6: Write a program to prompt for a file name, and then read through the file and look for lines of the form: X- DSPAM-
Confidence: 0.8475 When you encounter a line that starts with “X-DSPAM-Confidence:”pull apart the line to extract the
floating-point number on the line. Count these lines and then compute the total of the spam confidence values from these
lines. When you reach the end of the file, print out the average spam confidence.
Enter the file name: [Link]
Average spam confidence: 0.894128046745
8
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
Enter the file name: [Link]
Average spam confidence: 0.750718518519
Test your file on the [Link] and [Link] files.
7: Sometimes when programmers get bored or want to have a bit of fun, they add a harmless Easter Egg to their program.
Modify the program that prompts the user for the file name so that it prints a funny message when the user types in the
exact file name “na na boo boo”. The program should behave normally for all other files which exist and don’t exist. Here
is a sample execution of the program:
python [Link]
Enter the file name: [Link]
There were 1797 subject lines in [Link]
python [Link]
Enter the file name: [Link]
File cannot be opened: [Link]
python [Link]
Enter the file name: na na boo boo
NA NA BOO BOO TO YOU - You have been punk'd!
We are not encouraging you to put Easter Eggs in your programs; this is just an exercise.
Module III
1: Find all unique words in a file Shakespeare used over 20,000 words in his works. But how would you determine that?
How would you produce the list of all the words that Shakespeare used? Would you download all his work, read it and
track all unique words by hand? Let’s use Python to achieve that instead. List all unique words, sorted in alphabetical
order, that are stored in a file [Link] containing a subset of Shakespeare’s work. Create a list of unique words, which
will contain the final result. Write a program to open the file [Link] and read it line by line. For each line, split the line
into a list of words using the split function. Foreach word, check to see if the word is already in the list of unique words. If
the word is not in the list of unique words, add it to the list. When the program completes, sort and print the list of unique
words in alphabetical order.
Enter file: [Link]
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft',
'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
2: Minimalist Email Client. MBOX (mail box) is a popular file format to store and share a collection of emails. This was
used by early email servers and desktop apps. Without getting into too many details, MBOX is a text file, which stores
emails consecutively. Emails are separated by a special line which starts with From (notice the space). Importantly, lines
starting with From: (notice the colon) describes the email itself and does not act as a separator. Imagine you wrote a
minimalist email app, that lists the email of the senders in the user’s Inbox and counts the number of emails. Write a
program to read through the mail box data and when you find line that starts with “From”, you will split the line into
words using the split function. We are interested in who sent the message, which is the second word on the From line.
3: Rewrite the program that prompts the user for a list of numbers and prints out the maximum and minimum of the
numbers at the end when the user enters “done”. Write the program to store the numbers the user enters in a list and use
the max() and min() functions to compute the maximum and minimum numbers after the loop completes.
Enter a number: 6
Enter a number: 2
Enter a number: 9
Enter a number: 3
Enter a number: 5
Enter a number: done
Maximum: 9.0
9
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
Minimum: 2.0
4: Write a program that categorizes each mail message by which day of the week the commit was done. To do this look for
lines that start with “From”, then look for the third word and keep a running count of each of the days of the week. At the
end of the program print out the contents of your dictionary (order does not matter). Sample Line:
From [Link]@[Link] Sat Jan 5 09:14:16 2008
Sample Execution:
python [Link]
Enter a file name: [Link]
{'Fri': 20, 'Thu': 6, 'Sat': 1}
5: Write a program to read through a mail log, build a his- togram using a dictionary to count how many messages have
come from each email address, and print the dictionary.
Enter file name: [Link]
{'[Link]@[Link]': 1, 'louis@[Link]': 3,
'cwen@[Link]': 5, 'antranig@[Link]': 1,
'rjlowe@[Link]': 2, 'gsilver@[Link]': 3,
'[Link]@[Link]': 4, 'wagnermr@[Link]': 1,
'zqian@[Link]': 4, '[Link]@[Link]': 2,
'ray@[Link]': 1}
6: Add code to the above program to figure out who has the most messages in the file. After all the data has been read and
the dic- tionary has been created, look through the dictionary using a maximum loop (see Chapter 5: Maximum and
minimum loops) to find who has the most messages and print how many messages the person has.
Enter a file name: [Link]
cwen@[Link] 5
Enter a file name: [Link]
zqian@[Link] 195
7: This program records the domain name (instead of the address) where the message was sent from instead of who the
mail came from (i.e., the whole email address). At the end of the program, print out the contents of your dictionary.
python [Link]
Enter a file name: [Link]
{'[Link]': 4, '[Link]': 6, '[Link]': 7,
'[Link]': 1, '[Link]': 1, '[Link]': 8}
8: Revise a previous program as follows: Read and parse the “From” lines and pull out the addresses from the line. Count
the num- ber of messages from each person using a dictionary. After all the data has been read, print the person with the
most commits by creating a list of (count, email) tuples from the dictionary. Then sort the list in reverse order and print
out the person who has the most commits.
Sample Line:
From [Link]@[Link] Sat Jan 5 09:14:16 2008
Enter a file name: [Link]
cwen@[Link] 5
Enter a file name: [Link]
zqian@[Link] 195
9: This program counts the distribution of the hour of the day for each of the messages. You can pull the hour from the
“From” line by finding the time string and then splitting that string into parts using the colon character. Once you have
10
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
accumulated the counts for each hour, print out the counts, one per line, sorted by hour as shown below. python
[Link]
Enter a file name: [Link]
04 3
06 1
07 1
09 2
10 3
11 6
14 1
15 2
16 4
17 2
18 1
19 1
10: Write a program that reads a file and prints the letters in decreasing order of frequency. Your program should convert
all the input to lower case and only count the letters a-z. Your program should not count spaces, digits, punctuation, or
anything other than the letters a-z. Find text samples from several different languages and see how
letter frequency varies between languages.
11: regular expression A language for expressing more complex search strings. A regular expression may contain special
characters that indicate that a search only matches at the beginning or end of a line or many other similar capabilities. wild card A
special character that matches any character. In regular expressions the wild-card character is the period.
12: Write a simple program to simulate the operation of the grep command on Unix. Ask the user to enter a regular
expression and count the number of lines that matched the regular expression:
$ python [Link]
Enter a regular expression: ^Author
[Link] had 1798 lines that matched ^Author
$ python [Link]
Enter a regular expression: ^Xmbox.
txt had 14368 lines that matched ^X-
$ python [Link]
Enter a regular expression: java$
[Link] had 4175 lines that matched java$
13: Write a program to look for lines of the form:
New Revision: 39772
Extract the number from each of the lines using a regular expression and the findall() method. Compute the average of the
numbers and print out the average as an integer.
Enter file:[Link]
38549
Enter file:[Link]
39756
Module IV
1. Explain what are Classes & Objects
11
Course Plan 2020-21 Even – Semester 6th
Electronics & Communication Engineering
2. Explain what are Classes & Objects programs in detail.
3. Explain what are Classes & Functions
4. Explain what are Classes & Functions programs in detail.
5. Explain what are Classes & methods
6. Explain what are Classes & methods programs in detail.
Module V
1: Change the socket program [Link] to prompt the user for the URL so it can read any web page. You can use
split('/') to break the URL into its component parts so you can extract the host name for the socket connect call. Add error
checking using try and except to handle the condition where the user enters an improperly formatted or non existent
URL.
2: Change your socket program so that it counts the number of characters it has received and stops displaying any text
after it has shown 3000 characters. The program should retrieve the entire docu- ment and count the total number of
characters and display the count of the number of characters at the end of the document.
3: Use urllib to replicate the previous exercise of (1) retrieving the document from a URL, (2) displaying up to 3000
characters, and (3) counting the overall number of characters in the document. Don’t worry about the headers for this
exercise, simply show the first 3000 characters of the document contents.
4: Change the [Link] program to extract and count para- graph (p) tags from the retrieved HTML document and
display the count of the paragraphs as the output of your program. Do not display the paragraph text, only count them.
Test your program on several small web pages as well as some larger web pages.
5: (Advanced) Change the socket program so that it only shows data after the headers and a blank line have been
received. Remember that recv receives characters (newlines and all), not lines.
13.0 University Result
Examination FCD FC SC % Passing
First time Introduced No
exam Previous
Prepared by Checked by
Prof. [Link] [Link] HOD Principal
12