SlideShare ist ein Scribd-Unternehmen logo
1 von 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)

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie Chapter 1 Basic Programming (Python Programming Lecture)

Ähnlich wie 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
 

Mehr von IoT Code Lab

Mehr von 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
 

Kürzlich hochgeladen

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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
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
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
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 Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
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
 
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
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
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
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Kürzlich hochgeladen (20)

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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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_...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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Ă...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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 Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .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
 
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)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
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Ữ Â...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
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...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

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