BSc CS sem 1 Programming with Python- I techmax/notes Download




Objectives The objective of this paper is to introduce various concepts of programming to the students using Python. Expected learning outcomes 1) Students should be able to understand the concepts of programming before actually starting to write programs. 2) Students should be able to develop logic for Problem Solving. 3) Students should be made familiar about the basic constructs of programming such as data, operations, conditions, loops, functions etc. 4) Students should be able to apply the problem solving skills using syntactically simple language i.e. Python (version: 3.X or higher) Unit I Reasons for Python as the learner’s first programming language. Introduction to the IDLE interpreter (shell) and its documentation. Expression evaluation: similarities and differences compared to a calculator; expressions and operators of types int, float, boolean. Built-in function type. Operator precedence. Enumeration of simple and compound statements. The expression statement. The assert statement, whose operand is a boolean expression (values true or false). The assignment statement, dynamic binding of names to values, (type is associated with data and not with names); automatic and implicit declaration of variable names with the assignment statement; assigning the valueNone to a name. The del (delete) statement. Input/output with print and input functions. A statement list (semicolonseparated list of simple statements on a single line) as a single interpreter command. The import statement for already-defined functions and constants. The augmented assignment statement. The built-inhelp() function. Interactive and script modes of IDLE, running a script, restarting the shell. The compound statement def to define functions; the role of indentation for delimiting the body of a compound statement; calling a previously defined function. Compound data types str, tuple and list (enclosed in quotes, parentheses and brackets, respectively). Indexing individual elements within these types. Strings and tuples are immutable, lists are mutable. Built-in functions min, max, sum. Interactive solution of model problems, (e.g., finding the square root of a number or zero of a function), by repeatedly executing the body of a loop (where the body is a statement list). 15 L 6 Unit II Advantages of functions, function parameters, formal parameters, actual parameters, global and local variables. The range function, the iterative for statement. The conditional statements if, if-else, if-elif-else. The iterative statements while, while-else, for-else. The continue statement to skip over one iteration of a loop, the break statement to exit the loop. Nested compound statements. Dictionaries: concept of key-value pairs, techniques to create, update and delete dictionary items. Problem-solving using compound types and statements. 15 L Unit III Anonymous functions. List comprehensions. Gentle introduction to object-oriented programming; using the built-in dir() function, enumerate the methods of strings, tuples, lists, dictionaries. Using these methods for problem-solving with compound types. 15 L Text books: 1. Magnus Lie Hetland, Beginning Python: From Novice to Professional, Apress 2. Paul Gries, et al., Practical Programming: An Introduction to Computer Science Using Python 3, Pragmatic Bookshelf, 2/E 2014 Additional References: 1. Charles Dierbach, Introduction to Computer Science using Python, Wiley, 2013 2. Paul Gries , Jennifer Campbell, Jason Montojo, Practical Programming: An Introduction to Computer Science Using Python 3, Pragmatic Bookshelf, 2/E 2014 3. Adesh Pandey, Programming Languages – Principles and Paradigms, Narosa, 2008