COMPUTER PROGRAMMING USING PYTHON
RATIONALE
This course introduces to the students the Python language. Upon completion of this course, the student will be able to write non trivial Python programs dealing with a wide variety of subject matter domains. Topics include language components, the IDLE/IDE
environment, control flow constructs, strings, I/O, collections, classes, modules, and regular expressions.
LEARNING OUTCOMES
After undergoing the course, the students will be able to:
- execute Python code in a variety of environments
- use correct Python syntax in Python programs
- use the correct Python control flow construct
- write Python programs using various collection data types
- write home grown Python functions
- use standard Python modules such as os, sys, math, and time
- trap various errors via the Python Exception Handling model
- use the IO model in Python to read and write disk files
- create their own classes and use existing Python classes.
- understand and use the Object Oriented paradigm in Python programs
- use the Python Regular Expression capabilities for data verification
DETAILED CONTENTS
1.Introduction
- Brief History of Python
- Python Versions
- Installing Python
- Environment Variables
- Executing Python from the Command Line
- IDLE
- Editing Python Files
- Python Documentation
- Getting Help
- Dynamic Types
- Python Reserved Words
- Naming Conventions
2.Basic Python Syntax
- Basic Syntax
- Comments
- String Values
- String Methods
- The format Method
- String Operators
- Numeric Data Types
- Conversion Functions
- Simple Output
- Simple Input
- The % Method
- The print Function
3.Language Components
- Indenting Requirements
- The if Statement
- Relational and Logical Operators
- Bit Wise Operators
- The while Loop
- break and continue
- The for Loop
4.Collections
- Introduction
- Lists
- Tuples
- Sets
- Dictionaries
- Sorting Dictionaries
- Copying Collections
- Summary
5.Functions
- Introduction
- Defining Your Own Functions
- Parameters
- Function Documentation
- Keyword and Optional Parameters
- Passing Collections to a Function
- Variable Number of Arguments
- Scope
- Functions – “First Class Citizens”
- Passing Functions to a Function
- map
- filter
- Mapping Functions in a Dictionary
- Lambda
- Inner Functions
- Closures
6.Modules
- Modules
- Standard Modules – sys
- Standard Modules – math
- Standard Modules – time
- The dir Function
7.Exceptions
- Errors
- Runtime Errors
- The Exception Model
- Exception Hierarchy
- Handling Multiple Exceptions
- Raise
- assert
8.Input and Output
- Introduction
- Data Streams
- Creating Your Own Data Streams
- Access Modes
- Writing Data to a File
- Reading Data From a File
- Additional File Methods
- Using Pipes as Data Streams
- Handling IO Exceptions
9.Classes in Python
- Classes in Python
- Principles of Object Orientation
- Creating Classes
- Instance Methods
- File Organization
- Special Methods
- Class Variables
- Inheritance
- Polymorphism
10.Regular Expressions
- Introduction
- Simple Character Matches
- Special Characters
- Character Classes
- Quantifiers
- The Dot Character
- Greedy Matches
- Grouping
- Matching at Beginning or End
- Match Objects
- Substituting
- Splitting a String
- Compiling Regular Expressions
- Flags
LIST OF PRACTICALS
- Getting started with Python and IDLE in interactive and batch modes
- What do the following string methods do?
- lower
- count
- replace
3.Write instructions to perform each of the steps below
- Create a string containing at least five words and store it in a variable.
- Print out the string.
- Convert the string to a list of words using the string split method.
- Sort the list into reverse alphabetical order using some of the list methods (you might need to use dir(list) or help(list) to find appropriate methods).
- Print out the sorted, reversed list of words.
4.Write a program that determines whether the number is prime.
What is your favorite number? 24
24 is not prime
What is your favorite number? 31
31 is prime
5.Find all numbers which are multiple of 17, but not the multiple of 5, between 2000 and 2500?
6.Swap two integer numbers using a temporary variable. Repeat the exercise using the code format: a, b = b, a. Verify your results in both the cases.
7.Find the largest of n numbers, using a user defined function largest().
8.Write a function my Reverse() which receives a string as an input and returns the reverse of the string.
10.Check if a given string is palindrome or not.
11.WAP to convert Celsius to Fahrenheit
12.Find the ASCII value of charades
13.WAP for simple calculator
INSTRUCTIONAL STRATEGY
Teachers should lay emphasis on practicals and experts from industries may be invited to
deliver lectures and share experiences with the students.
MEANS OF ASSESSMENT
− Assignments and quiz/class tests, mid-term and end-term written tests
− Software installation, operation, development
− Actual laboratory and practical work exercises
− Viva-voce