Docsity

Python Notes from Basic to Advanced, Lecture notes of Computer Programming

Partial preview of the text

Download Python Notes from Basic to Advanced and more Lecture notes Computer Programming in PDF only on Docsity!

Problem Solving using Python

(ITFC0101)

Introduction, IDE, Program, Problem Solving

Course Outline/Curriculum & Lecture/Tutorial Count

Module No. Topics

1

Computational Thinking and Problem-Solving: Identification of Computational Problems -Algorithms, building blocks of algorithms (statements, state, control flow, functions), notation (pseudo code, flow chart, programming language), algorithmic problem solving, simple strategies for developing algorithms (iteration, recursion). Data Types, Expressions, and Statements: Python interpreter and interactive mode, debugging; values and types: int, float, Boolean, string, and list; variables, expressions, statements, tuple assignment, precedence of operators, comments.

2

Control Flow Functions, and Strings: Conditions - Boolean values and operators, conditional (if), alternative (if-else), chained conditional (if-elif-else); Iteration - state, while, for, break, continue, pass; Fruitful functions - return values, parameters, local and global scope, function composition, recursion; Strings

  • string slices, immutability, string functions and methods, string module; Lists as arrays.

3

Lists, Tuples, Dictionaries: Lists - list operations, list slices, list methods, list loop, mutability, aliasing, cloning lists, list parameters; Tuples - tuple assignment, tuple as a return value; Dictionaries - operations and methods; advanced list processing, list comprehension. Files, Modules, Packages: Files and exceptions: text files, reading and writing files, format operator; command line arguments, errors and exceptions, handling exceptions, modules packages.

Suggested Books

1. Yashavant Kanetkar, “Let Us Python”, 6 th^ **Edition, BPB publisher, 2023

  1. Allen B. Downey, “Think Python: How to Think like a Computer Scientist”, 2nd** Edition, O’Reilly Publishers, 2016.
  2. Karl Beecher, “Computational Thinking: A Beginner's Guide to Problem-Solving and Programming”, 1st Edition, BCS Learning & Development Limited, 2017.
  3. Kenneth A. Lambert, “Fundamentals of Python: First Programs”, CENGAGE Learning, 2012.

Some terms you will frequently encounter

  • High-level language
  • Low-level language
  • Portable
  • Python interpreter
  • Python prompt
  • Script

Python Prompt

IDE

Integrated Development environment

  • For Python (and many other programming languages) there are programs that include both a text editor and a way to interact with the interpreter.
  • We call these development environments (sometimes Integrated Development Environment or IDE).

Programming Methodology

  • Problem solving
    • Problem statement and analysis.
    • Develop a high-level algorithm.
    • Develop a low-level algorithm.
  • Coding
    • Choose a programming language.
    • Code the program using the selected algorithm.
    • Test the program and correct the errors.

Properties of Algorithm

Definition— Solution to a programming problem.

- Input: 0 or more - Output: 1 or more - Finiteness: Should terminate within finite time, OR after finite iterations - Deterministic / Definiteness: Non-ambiguous - Task oriented steps: All steps should have meaningful task e.g. x=x //Useless - Generic: Steps should be language independent

Example

Problem Statement: Find the average of a given list of numbers

  • High level algorithm
    1. Find the SUM of the given numbers
    2. Find the COUNT of the given numbers
    3. AVERAGE is SUM/COUNT

Basic Building Blocks of Algorithms

  • Statement
  • State
  • Control Flow
  • Function

Basic Building Blocks of Algorithms

Statements

Statement: A single action in a computer

In a computer statements might include some of the following actions

  • Input data-information given to the program
  • Process data-perform operation on a given input
  • Output data-processed result

Basic Building Blocks of Algorithms

Control Flow

Sequence: All the instructions are executed one after another is called sequence execution.

Example: Addition of two numbers

Step 1: Start

Step 2: get a,b

Step 3: calculate c=a+b

Step 4: Display c

Step 5: Stop

Basic Building Blocks of Algorithms

Control Flow

Selection: Statement causes the program control to be transferred to a specific part of the program based upon the condition.

If the conditional test is true, one part of the program will be executed, otherwise it will execute the other part of the program.

Example: Write an algorithm to check whether he is eligible to vote?

Step 1: Start

Step 2: Get age

Step 3: if age >= 18 print “Eligible to vote”

Step 4: else print “Not eligible to vote”

Step 6: Stop