SlideShare a Scribd company logo
1 of 47
PYTHON
PROGRAMMING
Chapter 1
Basic Programming
Topic
• Operator
• Arithmetic Operation
• Assignment Operation
• Arithmetic Operation More Example
• More Built in Function Example
• More Math Module Example
Operator in Python
• Operators are special symbols in that carry out arithmetic or logical
computation.
• The value that the operator operates on is called the operand.
• Type of Operator in Python
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Bitwise operators
• Identity operators
• Membership operators
PYTHON
PROGRAMMING
Chapter 1
Lecture 1.1.0
Basic Arithmetic Operator
Arithmetic Operator in Python
Operation Operator
Addition +
Subtraction -
Multiplication *
Division /
Floor Division //
Exponentiation **
Modulo %
Assignment Operator in Python
Operation Operator
Assign =
Add AND Assign +=
Subtract AND Assign -=
Multiply AND Assign *=
Divide AND Assign /=
Modulus AND Assign %=
Exponent AND Assign **=
Floor Division Assign //=
Note: Logical and Bitwise Operator can be used with assignment.
Summation of two number
a = 5
b = 4
sum = a + b
print(sum)
Summation of two number – User Input
a = int(input())
b = int(input())
sum = a + b
print(sum)
Difference of two number
a = int(input())
b = int(input())
diff = a - b
print(diff)
Product of two number
a = int(input())
b = int(input())
pro = a * b
print(pro)
Quotient of two number
a = int(input())
b = int(input())
quo = a / b
print(quo)
Reminder of two number
a = int(input())
b = int(input())
rem = a % b
print(rem)
Practice Problem 1.1
Input two Number form User and calculate the followings:
1. Summation of two number
2. Difference of two number
3. Product of two number
4. Quotient of two number
5. Reminder of two number
Any Question?
Like, Comment, Share
Subscribe
PYTHON
PROGRAMMING
Chapter 1
Lecture 1.1.1
More Arithmetic Operator
Floor Division
a = int(input())
b = int(input())
floor_div = a // b
print(floor_div)
a = float(input())
b = float(input())
floor_div = a // b
print(floor_div)
a = 5
b = 2
quo = a/b
= 5/2
= 2.5
quo = floor(a/b)
= floor(5/2)
= floor(2.5)
= 2
Find Exponent (a^b). [1]
a = int(input())
b = int(input())
# Exponent with Arithmetic Operator
# Syntax: base ** exponent
exp = a ** b
print(exp)
Find Exponent (a^b). [2]
a = int(input())
b = int(input())
# Exponent with Built-in Function
# Syntax: pow(base, exponent)
exp = pow(a,b)
print(exp)
Find Exponent (a^b). [3]
a = int (input())
b = int(input())
# Return Modulo for Exponent with Built-in Function
# Syntax: pow(base, exponent, modulo)
exp = pow(a,b,2)
print(exp)
a = 2
b = 4
ans = (a^b)%6
= (2^4)%6
= 16%6
= 4
Find Exponent (a^b). [4]
a = int(input())
b = int(input())
# Using Math Module
import math
exp = math.pow(a,b)
print(exp)
Find absolute difference of two number. [1]
a = int(input())
b = int(input())
abs_dif = abs(a - b)
print(abs_dif)
a = 4
b = 2
ans1 = abs(a-b)
= abs(4-2)
= abs(2)
= 2
ans2 = abs(b-a)
= abs(2-4)
= abs(-2)
= 2
Find absolute difference of two number. [2]
import math
a = float(input())
b = float(input())
fabs_dif = math.fabs(a - b)
print(fabs_dif)
Built-in Function
• abs(x)
• pow(x,y[,z])
https://docs.python.org/3.7/library/functions.html
Practice Problem 1.2
Input two number from user and calculate the followings: (use
necessary date type)
1. Floor Division with Integer Number & Float Number
2. Find Exponential (a^b) using Exponent Operator, Built-in
pow function & Math Module pow function
3. Find Exponent with modulo (a^b%c)
4. Find absolute difference of two number using Built-in
abs function & Math Module fabs function
Any Question?
Like, Comment, Share
Subscribe
PYTHON
PROGRAMMING
Chapter 1
Lecture 1.2
Arithmetic Operation Example
Average of three numbers.
a = float(input())
b = float(input())
c = float(input())
sum = a + b + c
avg = sum/3
print(avg)
Area of Triangle using Base and Height.
b = float(input())
h = float(input())
area = (1/2) * b * h
print(area)
Area of Triangle using Length of 3 sides.
import math
a = float(input())
b = float(input())
c = float(input())
s = (a+b+c) / 2
area = math.sqrt(s*(s-a)*(s-b)*(s-c))
print(area)
𝑎𝑟𝑒𝑎 = 𝑠 ∗ (s−a)∗(s−b)∗(s−c)
𝑠 =
𝑎 + 𝑏 + 𝑐
2
Area of Circle using Radius.
import math
r = float(input())
pi = math.pi
area = pi * r**2
# area = pi * pow(r,2)
print(area)
𝑎𝑟𝑒𝑎 = 3.1416 ∗ 𝑟2
Convert Temperature Celsius to Fahrenheit.
celsius = float(input())
fahrenheit = (celsius*9)/5 + 32
print(fahrenheit)
𝐶
5
=
𝐹 − 32
9
𝐹 − 32 ∗ 5 = 𝐶 ∗ 9
𝐹 − 32 =
𝐶 ∗ 9
5
𝐹 =
𝐶 ∗ 9
5
+ 32
Convert Temperature Fahrenheit to Celsius.
fahrenheit = float(input())
celsius = (fahrenheit-32)/9 * 5
print(celsius)
𝐶
5
=
𝐹 − 32
9
𝐶 ∗ 9 = 𝐹 − 32 ∗ 5
𝐶 =
𝐹 − 32 ∗ 5
9
Convert Second to HH:MM:SS.
# 1 Hour = 3600 Seconds
# 1 Minute = 60 Seconds
totalSec = int(input())
hour = int(totalSec/3600)
min_sec = int(totalSec%3600)
minute = int(min_sec/60)
second = int(min_sec%60)
print("{}H {}M
{}S".format(hour,minute,second))
#print(f"{hour}H {minute}M {second}S")
# 1 Hour = 3600 Seconds
# 1 Minute = 60 Seconds
totalSec = int(input())
hour = totalSec//3600
min_sec = totalSec%3600
minute = min_sec//60
second = min_sec%60
print("{}H {}M
{}S".format(hour,minute,second))
#print(f"{hour}H {minute}M {second}S")
Math Module
• math.pow(x, y)
• math.sqrt(x)
• math.pi
https://docs.python.org/3.7/library/math.html
Practice Problem 1.3
1. Average of three numbers.
2. Area of Triangle using Base and Height.
3. Area of Triangle using Length of 3 sides.
4. Area of Circle using Radius.
5. Convert Temperature Celsius to Fahrenheit.
6. Convert Temperature Fahrenheit to Celsius.
7. Convert Second to HH:MM:SS.
Any Question?
Like, Comment, Share
Subscribe
PYTHON
PROGRAMMING
Chapter 1
Lecture 1.2
More Operator
Comparison Operator in Python
Operation Operator
Equality ==
Not Equal !=
Greater Than >
Less Than <
Greater or Equal >=
Less or Equal <=
Logical Operator in Python
Operation Operator
Logical And and
Logical Or or
Logical Not not
Bitwise Operator in Python
Operation Operator
Bitwise And &
Bitwise Or |
Bitwise Xor ^
Left Shift <<
Right Shift >>
Other Operator in Python
• Membership Operator (in, not in)
• Identity Operator (is, not is)
Any Question?
Like, Comment, Share
Subscribe
Chapter 1 Basic Programming (Python Programming Lecture)

More Related Content

What's hot

Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in PythonMarc Garcia
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonShivam Mitra
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in pythonJothi Thilaga P
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in PythonJuan-Manuel Gimeno
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slidesrfojdar
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programmingizahn
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the StyleJuan-Manuel Gimeno
 

What's hot (20)

Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Python libraries
Python librariesPython libraries
Python libraries
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Python programming
Python  programmingPython  programming
Python programming
 
Python for loop
Python for loopPython for loop
Python for loop
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
 
Python basic
Python basicPython basic
Python basic
 
Python ppt
Python pptPython ppt
Python ppt
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the Style
 

Similar to Chapter 1 Basic Programming (Python Programming Lecture)

Similar to Chapter 1 Basic Programming (Python Programming Lecture) (20)

Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
C Operators
C OperatorsC Operators
C Operators
 
Function recap
Function recapFunction recap
Function recap
 
Function recap
Function recapFunction recap
Function recap
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Function pointer
Function pointerFunction pointer
Function pointer
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
 
functions
functionsfunctions
functions
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
 

More from IoT Code Lab

More from IoT Code Lab (8)

7.1 html lec 7
7.1 html lec 77.1 html lec 7
7.1 html lec 7
 
6.1 html lec 6
6.1 html lec 66.1 html lec 6
6.1 html lec 6
 
5.1 html lec 5
5.1 html lec 55.1 html lec 5
5.1 html lec 5
 
4.1 html lec 4
4.1 html lec 44.1 html lec 4
4.1 html lec 4
 
3.1 html lec 3
3.1 html lec 33.1 html lec 3
3.1 html lec 3
 
2.1 html lec 2
2.1 html lec 22.1 html lec 2
2.1 html lec 2
 
1.1 html lec 1
1.1 html lec 11.1 html lec 1
1.1 html lec 1
 
1.0 intro
1.0 intro1.0 intro
1.0 intro
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Recently uploaded (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Chapter 1 Basic Programming (Python Programming Lecture)

  • 1.
  • 3. Topic • Operator • Arithmetic Operation • Assignment Operation • Arithmetic Operation More Example • More Built in Function Example • More Math Module Example
  • 4. Operator in Python • Operators are special symbols in that carry out arithmetic or logical computation. • The value that the operator operates on is called the operand. • Type of Operator in Python • Arithmetic operators • Assignment operators • Comparison operators • Logical operators • Bitwise operators • Identity operators • Membership operators
  • 6. Arithmetic Operator in Python Operation Operator Addition + Subtraction - Multiplication * Division / Floor Division // Exponentiation ** Modulo %
  • 7. Assignment Operator in Python Operation Operator Assign = Add AND Assign += Subtract AND Assign -= Multiply AND Assign *= Divide AND Assign /= Modulus AND Assign %= Exponent AND Assign **= Floor Division Assign //= Note: Logical and Bitwise Operator can be used with assignment.
  • 8. Summation of two number a = 5 b = 4 sum = a + b print(sum)
  • 9. Summation of two number – User Input a = int(input()) b = int(input()) sum = a + b print(sum)
  • 10. Difference of two number a = int(input()) b = int(input()) diff = a - b print(diff)
  • 11. Product of two number a = int(input()) b = int(input()) pro = a * b print(pro)
  • 12. Quotient of two number a = int(input()) b = int(input()) quo = a / b print(quo)
  • 13. Reminder of two number a = int(input()) b = int(input()) rem = a % b print(rem)
  • 14. Practice Problem 1.1 Input two Number form User and calculate the followings: 1. Summation of two number 2. Difference of two number 3. Product of two number 4. Quotient of two number 5. Reminder of two number
  • 15. Any Question? Like, Comment, Share Subscribe
  • 16.
  • 18. Floor Division a = int(input()) b = int(input()) floor_div = a // b print(floor_div) a = float(input()) b = float(input()) floor_div = a // b print(floor_div) a = 5 b = 2 quo = a/b = 5/2 = 2.5 quo = floor(a/b) = floor(5/2) = floor(2.5) = 2
  • 19. Find Exponent (a^b). [1] a = int(input()) b = int(input()) # Exponent with Arithmetic Operator # Syntax: base ** exponent exp = a ** b print(exp)
  • 20. Find Exponent (a^b). [2] a = int(input()) b = int(input()) # Exponent with Built-in Function # Syntax: pow(base, exponent) exp = pow(a,b) print(exp)
  • 21. Find Exponent (a^b). [3] a = int (input()) b = int(input()) # Return Modulo for Exponent with Built-in Function # Syntax: pow(base, exponent, modulo) exp = pow(a,b,2) print(exp) a = 2 b = 4 ans = (a^b)%6 = (2^4)%6 = 16%6 = 4
  • 22. Find Exponent (a^b). [4] a = int(input()) b = int(input()) # Using Math Module import math exp = math.pow(a,b) print(exp)
  • 23. Find absolute difference of two number. [1] a = int(input()) b = int(input()) abs_dif = abs(a - b) print(abs_dif) a = 4 b = 2 ans1 = abs(a-b) = abs(4-2) = abs(2) = 2 ans2 = abs(b-a) = abs(2-4) = abs(-2) = 2
  • 24. Find absolute difference of two number. [2] import math a = float(input()) b = float(input()) fabs_dif = math.fabs(a - b) print(fabs_dif)
  • 25. Built-in Function • abs(x) • pow(x,y[,z]) https://docs.python.org/3.7/library/functions.html
  • 26. Practice Problem 1.2 Input two number from user and calculate the followings: (use necessary date type) 1. Floor Division with Integer Number & Float Number 2. Find Exponential (a^b) using Exponent Operator, Built-in pow function & Math Module pow function 3. Find Exponent with modulo (a^b%c) 4. Find absolute difference of two number using Built-in abs function & Math Module fabs function
  • 27. Any Question? Like, Comment, Share Subscribe
  • 28.
  • 30. Average of three numbers. a = float(input()) b = float(input()) c = float(input()) sum = a + b + c avg = sum/3 print(avg)
  • 31. Area of Triangle using Base and Height. b = float(input()) h = float(input()) area = (1/2) * b * h print(area)
  • 32. Area of Triangle using Length of 3 sides. import math a = float(input()) b = float(input()) c = float(input()) s = (a+b+c) / 2 area = math.sqrt(s*(s-a)*(s-b)*(s-c)) print(area) 𝑎𝑟𝑒𝑎 = 𝑠 ∗ (s−a)∗(s−b)∗(s−c) 𝑠 = 𝑎 + 𝑏 + 𝑐 2
  • 33. Area of Circle using Radius. import math r = float(input()) pi = math.pi area = pi * r**2 # area = pi * pow(r,2) print(area) 𝑎𝑟𝑒𝑎 = 3.1416 ∗ 𝑟2
  • 34. Convert Temperature Celsius to Fahrenheit. celsius = float(input()) fahrenheit = (celsius*9)/5 + 32 print(fahrenheit) 𝐶 5 = 𝐹 − 32 9 𝐹 − 32 ∗ 5 = 𝐶 ∗ 9 𝐹 − 32 = 𝐶 ∗ 9 5 𝐹 = 𝐶 ∗ 9 5 + 32
  • 35. Convert Temperature Fahrenheit to Celsius. fahrenheit = float(input()) celsius = (fahrenheit-32)/9 * 5 print(celsius) 𝐶 5 = 𝐹 − 32 9 𝐶 ∗ 9 = 𝐹 − 32 ∗ 5 𝐶 = 𝐹 − 32 ∗ 5 9
  • 36. Convert Second to HH:MM:SS. # 1 Hour = 3600 Seconds # 1 Minute = 60 Seconds totalSec = int(input()) hour = int(totalSec/3600) min_sec = int(totalSec%3600) minute = int(min_sec/60) second = int(min_sec%60) print("{}H {}M {}S".format(hour,minute,second)) #print(f"{hour}H {minute}M {second}S") # 1 Hour = 3600 Seconds # 1 Minute = 60 Seconds totalSec = int(input()) hour = totalSec//3600 min_sec = totalSec%3600 minute = min_sec//60 second = min_sec%60 print("{}H {}M {}S".format(hour,minute,second)) #print(f"{hour}H {minute}M {second}S")
  • 37. Math Module • math.pow(x, y) • math.sqrt(x) • math.pi https://docs.python.org/3.7/library/math.html
  • 38. Practice Problem 1.3 1. Average of three numbers. 2. Area of Triangle using Base and Height. 3. Area of Triangle using Length of 3 sides. 4. Area of Circle using Radius. 5. Convert Temperature Celsius to Fahrenheit. 6. Convert Temperature Fahrenheit to Celsius. 7. Convert Second to HH:MM:SS.
  • 39. Any Question? Like, Comment, Share Subscribe
  • 40.
  • 42. Comparison Operator in Python Operation Operator Equality == Not Equal != Greater Than > Less Than < Greater or Equal >= Less or Equal <=
  • 43. Logical Operator in Python Operation Operator Logical And and Logical Or or Logical Not not
  • 44. Bitwise Operator in Python Operation Operator Bitwise And & Bitwise Or | Bitwise Xor ^ Left Shift << Right Shift >>
  • 45. Other Operator in Python • Membership Operator (in, not in) • Identity Operator (is, not is)
  • 46. Any Question? Like, Comment, Share Subscribe