7. Topic
• Python Introduction
• What is Python?
• Story of Python
• Why Python
• Use of Python
• Python Download +
Installation
• Online Resource
• First Program - Hello
World
• Comment
• Variable + Data Type
• Variable Naming
Convention
• Input/ Output
• Type Casting
• Built in Function
7
11. Python – Story
• Created by Guido van Rossum
• The name Python was inspired by the BBC TV show Monty Python's
Flying Circus
11
12. Python – Story
• Created by Guido van Rossum
• The name Python was inspired by the BBC TV show Monty Python's
Flying Circus
• Implementation began in December 1989
• Initial Release (labeled version 0.9.0) => 20 February 1991
• Python 1.0 => January 1994
• Python 2.0 => 16 October 2000
12
13. Python – Story
• Created by Guido van Rossum
• The name Python was inspired by the BBC TV show Monty Python's
Flying Circus
• Implementation began in December 1989
• Initial Release (labeled version 0.9.0) => 20 February 1991
• Python 1.0 => January 1994
• Python 2.0 => 16 October 2000
• Python 3.0 => 3 December 2008
13
14. Python – Why?
• Easy to learn
• Open source
• One of the most influential programming languages
15
15. Python - Use
• Education
• Web Development
• Backend Development
• API Development
• Desktop GUI
• Scientific and Numeric
Analysis
• Data Science
• Data Analytics
• Artificial Intelligence
• Machine Learning
• Data Analysis
• Data Visualization
• Automation
16
37. Create First Python Program File
• Python IDLE
• File -> New File -> Save (/Save As) -> hello_world.py
• Write Python Program
• Run -> Run Module (/F5)
38
43. Comment
# Single Line Comment
"""
Multi
Line
Comment
"""
'''
Multi
Line
Comment
'''
44
44. First Python Program Modified 1
# First Python Program
# Program Name: Hello World
# Author Name: One Year Programming
# A Program to Print a text
print("Hello World")
45
45. First Python Program Modified 2
"""
First Python Program
Program Name: Hello World
Author Name: One Year Programming
A Program to Print a text
"""
print("Hello World")
46
46. First Python Program Modified 3
'''
First Python Program
Program Name: Hello World
Author Name: One Year Programming
A Program to Print a text
'''
print("Hello World")
47
58. Data Type
• str (String)
• int (Integer)
• float (Float)
• bool (Boolean)
• None (NoneType)
59
59. Variable Naming Convention
• Must begin with a letter (a - z, A - Z) or underscore (_)
• Other characters can be letters, numbers or _
• Variable names are case-sensitive
• Variables should be all lowercase
• Words in a variable name should be separated by an underscore
• Don't start name with a digit.
• Never use special symbols like !, @, #, $, %
• Reserved words cannot be used as a variable
https://visualgit.readthedocs.io/en/latest/pages/naming_convention.html
60
60. Practice Problem 0.1
1. Declare a Integer variable and print value with data type
2. Declare a Float variable and print value with data type
3. Declare a String variable and print value with data type
4. Declare a Boolean variable and print value with data type
5. Declare a NoneType variable and print value with data type
61
66. Input/Output + Data Type
#input a String
name = input("Input Your Name: ")
print(name)
print(type(name))
67
67. Input Your Name
# Solution 1:
# input a String and Display the
String
name = input()
print(name)
# Solution 2:
# input a String with Message in
print()
print("Input Your Name")
name = input()
print(name)
# Solution 3:
# input a String with Message in
input()
name = input("Input Your Name: ")
print(name)
# Solution 4:
#input a String and Know Datatype
name = input("Input Your Name: ")
print(name)
print(type(name))
69
68. Practice Problem 0.2
1. Input your Name and print the value
2. Input your Name with a massage and print the value
3. Input your Name with a massage in input() function and
print the value
4. Input your Name with a massage in input() function and
print the value with data type
71
72. Input an Integer Number [Con.][Data Type]
age = input()
print(age)
print(type(age))
• All Input is String in Python
• We have to Type Cast to convert String into
Integer.
75
73. Input an Integer Number (*)
age = input()
print(age)
print(type(age))
# Type Cast to Integer Number
age = int(age)
print(age)
print(type(age))
76
74. Input an Integer Number [Final]
age = int(input())
print(age)
print(type(age))
77
75. Input an Float Number
gpa = input()
print(gpa)
print(type(gpa))
78
76. Input an Float Number (*)
gpa = input()
print(gpa)
print(type(gpa))
# Type Cast to Float Number
gpa = float(gpa)
print(gpa)
print(type(gpa))
79
77. Input an Float Number [Final]
gpa = float(input())
print(gpa)
print(type(gpa))
80
80. Practice Problem 0.3
1. Input your age and print data with type (Be sure about
type conversion to integer)
2. Input your gpa and print data with type (Be sure about
type conversion to float)
83
83. Formatted I/O
name = input("What is Your Name: ")
print("Hello,", name)
roll = int(input("What is Your Roll: "))
print("Your roll is:", roll)
gpa = float(input("What is Your GPA: "))
print("Your GPA is", gpa)
86
84. Formatted I/O 2
name = input("What is Your Name: ")
roll = int(input("What is Your Roll: "))
gpa = float(input("What is Your GPA: "))
print(name, roll, gpa)
print(name, roll, gpa, sep=",")
87
85. Formatted I/O 3
#Input Name with Formatted Output
name = input("What is Your Name: ")
print("Hello,",name)
print("Hello,", name, "How are You", name, "?")
print("Hello,", name, "nHow are You", name, "?")
print("Hello, {}nHow are You {}?".format(name,name))
print(f"Hello, {name}nHow are You {name}?")
88
88. Topic
• Operator
• Arithmetic Operation
• Assignment Operation
• Arithmetic Operation Example
• More Built in Function Example
• Math Module Example
92
89. 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
93
92. 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.
96
93. Summation of two number
a = 5
b = 4
summation = a + b
print(summation)
97
94. Summation of two number – User Input
a = int(input())
b = int(input())
summation = a + b
print(summation)
98
95. Difference of two number
a = int(input())
b = int(input())
difference = a - b
print(difference)
99
96. Product of two number
a = int(input())
b = int(input())
product = a * b
print(product)
100
97. Quotient of two number
a = int(input())
b = int(input())
quotient = a / b
print(quotient)
101
98. Reminder of two number
a = int(input())
b = int(input())
reminder = a % b
print(reminder)
102
99. 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
103
102. 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
106
109. Find Exponent (a^b). [1]
a = int(input())
b = int(input())
# Exponent with Arithmetic Operator
# Syntax: base ** exponent
exp = a ** b
print(exp)
113
110. 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)
114
111. 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
115
112. Find Exponent (a^b). [4]
import math
a = int(input())
b = int(input())
# Using Math Module
exp = math.pow(a,b)
print(exp)
116
113. 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
117
114. Find absolute difference of two number. [2]
import math
a = float(input())
b = float(input())
fabs_dif = math.fabs(a - b)
print(fabs_dif)
118
117. 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
122
120. Average of three numbers.
a = float(input())
b = float(input())
c = float(input())
sum = a + b + c
avg = sum/3
print(avg)
125
121. Area of Triangle using Base and Height.
b = float(input())
h = float(input())
area = (1/2) * b * h
print(area)
126
122. 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
127
123. Area of Circle using Radius.
r = float(input())
pi = 3.1416
area = pi * r**2
print(area)
𝑎𝑟𝑒𝑎 = 3.1416 ∗ 𝑟2
128
124. Area of Circle using Radius.
import math
r = float(input())
pi = math.pi
area = pi * r**2
# area = pi * pow(r,2)
# area = pi * math.pow(r,2)
print(area)
129
𝑎𝑟𝑒𝑎 = 3.1416 ∗ 𝑟2
130. 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 Second to HH:MM:SS.
6. Temperature Conversion
1. Celsius (°C) ⇔ Fahrenheit (°F)
2. Celsius (°C) ⇔ Kelvin (K)
3. Fahrenheit (°F) ⇔ Kelvin (K)
135
𝐶
5
=
𝐹 − 32
9
𝐾 = 𝐶 + 273.15
131. Practice Problem 1.4 Unit Conversion
• Weight
• Pound
• Kilogram
• Gram
• Carat
• Ounce
• Area
• Foot^2
• Meter^2
• Inch^2
• CM^2
• Mile^2
• KM^2
• Acre
• Hectare
• Length
• Mile
• Kilometer
• Meter
• Yard
• Foot
• Centimeter
• Inch
• Volume
• Inch^3
• CM^3
• Foot^3
• Metre^3
• Yard^3
• Gallon
• Liter
• Currency
• Time