PYTHON
Prepared By
Dr. Nasim Hasan
1
, Contents
Table of Content........................................................Error! Bookmark not defined.
Chapter 1: Introduction to Python............................................................................... 4
1.2 What is Python? ................................................................................................ 4
1.3 History of Python .............................................................................................. 4
1.4 Why use Python? .............................................................................................. 4
1.5 Python syntax .................................................................................................... 4
1.6 Python data types .............................................................................................. 4
1.7 Python operators ............................................................................................... 4
1.8 Downloading & Installing Python .................................................................... 5
Chapter 2: Control Flow Statements .........................................................................10
2.1 If statements ....................................................................................................10
2.2 While loops .....................................................................................................11
2.3 For loops..........................................................................................................11
2.3 Break and continue statements........................................................................12
2.4 Exceptions .......................................................................................................13
Chapter 3: Functions .................................................................................................15
3.1 Defining functions...........................................................................................15
3.2 Calling functions .............................................................................................15
3.3 Passing arguments to functions .......................................................................15
3.4 Returning values from functions .....................................................................15
Chapter 4: Modules ...................................................................................................17
4.1 What is a module? ...........................................................................................17
4.2 Importing modules ..........................................................................................17
4.3 Using modules.................................................................................................17
4.4 Creating modules ............................................................................................17
Chapter 5: Object-Oriented Programming ................................................................19
Chapter 6: Input and Output......................................................................................20
6.1 Reading input from the user ............................................................................20
2
, 6.2 Writing output to the screen ............................................................................20
6.3 Reading and writing files..............................................................................20
Chapter 8: List of experiment Basic Level ...............................................................21
8.1 Find the maximum of two numbers: ...........................................................21
8.2 Find the sum of two numbers: .....................................................................21
8.3 Find the difference of two numbers: ...............................................................22
8.4 Find the product of two numbers: ...................................................................22
8.5 Find the quotient of two numbers: ..................................................................22
8.6 Find the remainder of two numbers: ...............................................................23
8.7 Check if a number is even or odd: ..................................................................23
8.8 Check if a number is positive or negative: .....................................................24
8.9 Check if a number is prime: ............................................................................24
8.10 Check if a number is Armstrong: ..............................................................25
8.11 Check if two strings are anagrams: ...........................................................25
8.12 Find the factorial of a number:..................................................................26
8.13 Find the Fibonacci sequence: .....................................................................26
8.14 Find the GCD of two numbers: .....................Error! Bookmark not defined.
8.15 Calculate the area of a circle. .....................Error! Bookmark not defined.
8.16 Convert a temperature from Fahrenheit to Celsius. ...............................28
3