SlideShare a Scribd company logo
1 of 33
Introduction to
Python
Welcome
Congratulations for deciding to participate
in a 7 days of Introduction to Python
Course.
In this course you will learn the basics of
programming using Python.
Course Introduction
This course is designed for beginners and
intermediate who want to learn python
programming language.
In this course the topics are broken down
into 7 days, where each day contains several
topics with easy-to-understand
explanations, real-world examples, many
hands on exercises and a final project.
Why Python?
Python is a programming language which is
very close to human language and because
of that it is easy to learn and use.
Python is used by various industries and
companies (including Google).
It has been used to develop web
applications, desktop applications, system
administration, and machine learning
libraries.
Installing Python
 To run a python script you need to install python.
Let's download python from
https://www.python.org/.
Installing VS Code
 Visual Studio Code is a code editor (much like
any other editor like Notepad) helpful in writing
and editing codes.
 We download it from here
https://code.visualstudio.com/
Basic Data-types
 Boolean
A boolean data type is either a True or False value. T and F
should be always uppercase.
 Integers (default for numbers)
z = 5
 Floats
x = 3.1416
 Complex Numbers
x = 1+2j
Basic Data-types
 Strings
• Can use “ ” or ‘ ’ to specify strings
• a = “Nepal”
• b = ‘Kantipur Engineering College’
• “abc” == ‘abc’
• Use “ ” if ’ already in string eg: “matt’s”
• Use triple double-quotes for multi-line strings or strings
than contain both ‘ and “ inside of them:
“““a‘b“c”””
Checking Data Types
 To check the data type of certain data/variable we
use the type function.
>>> type(15)
<class ‘int’>
>>> type(3.14)
<class ‘float’>
>>> type(1+2j)
<class ‘complex’>
>>> str = “Hello World”
>>> type(str)
<class ‘string’>
Naming Rules
 Names are case sensitive and cannot start with a
number.
 They can contain letters, numbers, and
underscores.
 bob Bob _bob _2_bob_ bob_2 BoB
 There are some reserved words:
and, assert, break, class, continue, def, del, elif, else,
except, exec, finally, for, from, global, if, import, in, is,
lambda, not, or, pass, print, raise, return, try, while
 Can’t do this
• for = 12 #for is a reserved word
Assignment
 Assign value to variables
>>> x = 2
 You can assign to multiple names at the same time
>>> x, y = 2, 3
>>> x
2
>>> y
3
 This makes it easy to swap values
>>> x, y = y, x
 Assignments can be chained
>>> a = b = x = 2
Mathematical Operators
Mathematical Operators
 Exercise: Find an Euclidian distance between (2, 3) and
(10, 8)
Mathematical Operators
 Exercise: For a given temperature in celsius stored in
variable ‘t_c’, get the Fahrenheit temperature in ‘t_f’ and
display result.
• Let t_c = 100
• ans = 212
Checking Data Types
 Exercise: What would be the data-type of?
>>> a = 4/3
>>> type(a)
>>> n = 4//3
>>> type(a)
>>> num = ‘2080’
>>> type(num)
Type Casting
 Converting one data type to another data type.
 We use int(), float(), str()
>> # float to int
>> gravity = 9.81
>> print(int(gravity))
Type Casting
 When we do arithmetic operations string numbers
should be first converted to int or float otherwise it
will return an error.
>> #str to int or float
>> num_str = '10.6‘
>> print('num_int', int(num_str))
>> print('num_float', float(num_str))
Comparison Operators
Comparison Operators
 In programming we compare values, we use
comparison operators to compare two values. We
check if a value is greater or less or equal to other
value.
>> 2 == 2
>> 3.14 == 3.1416
>> print(123 == ‘123’)
>> print(123 == int(‘123’))
>> a = ‘mango’
>> b = ‘orange’
>> a == b
>> a < b What does this show?
Logical Operators
Logical Operators
 Logical operators are used to combine conditional
statements:
>> 2 == 2 and 2 < 4
True
>> print()
>>
>> a = ‘mango’
>> b = ‘orange’
>> a == b
>> a < b What does this show?
Conditionals
 In python the key word if is used to check if a
condition is true and to execute the block code.
Remember the indentation after the colon.
a = 10
if a > 3:
print(a, “is greater than 3”)
 if else
a = 3
if a > 0:
print(a, “is positive number”)
else:
print(a, “is negative”)
Conditionals
 if elif else
a = 3
if a > 0:
print(a, “is positive number”)
elif a < 0:
print(a, “is negative number”)
else:
print(a, “is zero”)
Operators and Conditionals
 Exercise:
 How do you check if a number is between 5 and 10
inclusive?
Note: Use if statement here
>>> if condition_1 and condition_2:
... choice_1
>>> else:
... choice_2
>>>
Operators and Conditionals
 Exercise:
 How do you check if a number is even or not using
python?
Note: Use if statement here
>>> if condition:
... choice_1
>>> else:
... choice_2
>>>
Program for the Day
Calculate Electricity Bill (15A)
KWh Minimum Charge Charge per KWh
0 to 20 50 4.00
21 to 30 75 6.50
31 to 50 75 8.00
51 to 100 100 9.50
101 to 250 125 9.50
250 above 175 11
Ans: 2330 for 250 units
Loops
 In programming we also do lots of repetitive tasks. In order
to handle repetitive task programming languages use loops.
Python programming language also provides the following
types of two loops:
• while loop
• for loop
While Loop
count = 0
while count < 5:
print(count)
count = count + 1 #prints from 0 to 4
for Loop
# syntax
for iterator in range(start, end, step):
#loop statements
for i in range(1,10,1):
print(i)
for Loop
num_list = [1,2,3,4,5]
for num in num_list:
print(num)
it_companies = ['Facebook', 'Google', 'Microsoft',
'Apple', 'IBM', 'Oracle',
‘Amazon‘]
for company in it_companies:
print(company)
Program for the Day
Student Grading SEE and NEB
Program for the Day
Student Grading SEE and NEB
 For a given students’ mark in percentage, display
letter grade for each student.
marks = 90
Your code should display “Outstanding”
Program for the Day
Student Grading SEE and NEB
 For a list of students’ marks in percentage, display
letter grade for each student.
marks = [95, 42, 78, 45, 89, 90]
Use for loop

More Related Content

Similar to introduction to python in english presentation file

Similar to introduction to python in english presentation file (20)

Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Introduction To Python.pptx
Introduction To Python.pptxIntroduction To Python.pptx
Introduction To Python.pptx
 
Python programing
Python programingPython programing
Python programing
 
Python programming
Python  programmingPython  programming
Python programming
 
TOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfTOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdf
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
 
Python
PythonPython
Python
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
 
Python basics
Python basicsPython basics
Python basics
 
Foundations of Programming Part I
Foundations of Programming Part IFoundations of Programming Part I
Foundations of Programming Part I
 

Recently uploaded

Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
IJECEIAES
 
Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...
IJECEIAES
 

Recently uploaded (20)

Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 

introduction to python in english presentation file

  • 2. Welcome Congratulations for deciding to participate in a 7 days of Introduction to Python Course. In this course you will learn the basics of programming using Python.
  • 3. Course Introduction This course is designed for beginners and intermediate who want to learn python programming language. In this course the topics are broken down into 7 days, where each day contains several topics with easy-to-understand explanations, real-world examples, many hands on exercises and a final project.
  • 4. Why Python? Python is a programming language which is very close to human language and because of that it is easy to learn and use. Python is used by various industries and companies (including Google). It has been used to develop web applications, desktop applications, system administration, and machine learning libraries.
  • 5. Installing Python  To run a python script you need to install python. Let's download python from https://www.python.org/.
  • 6. Installing VS Code  Visual Studio Code is a code editor (much like any other editor like Notepad) helpful in writing and editing codes.  We download it from here https://code.visualstudio.com/
  • 7. Basic Data-types  Boolean A boolean data type is either a True or False value. T and F should be always uppercase.  Integers (default for numbers) z = 5  Floats x = 3.1416  Complex Numbers x = 1+2j
  • 8. Basic Data-types  Strings • Can use “ ” or ‘ ’ to specify strings • a = “Nepal” • b = ‘Kantipur Engineering College’ • “abc” == ‘abc’ • Use “ ” if ’ already in string eg: “matt’s” • Use triple double-quotes for multi-line strings or strings than contain both ‘ and “ inside of them: “““a‘b“c”””
  • 9. Checking Data Types  To check the data type of certain data/variable we use the type function. >>> type(15) <class ‘int’> >>> type(3.14) <class ‘float’> >>> type(1+2j) <class ‘complex’> >>> str = “Hello World” >>> type(str) <class ‘string’>
  • 10. Naming Rules  Names are case sensitive and cannot start with a number.  They can contain letters, numbers, and underscores.  bob Bob _bob _2_bob_ bob_2 BoB  There are some reserved words: and, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while  Can’t do this • for = 12 #for is a reserved word
  • 11. Assignment  Assign value to variables >>> x = 2  You can assign to multiple names at the same time >>> x, y = 2, 3 >>> x 2 >>> y 3  This makes it easy to swap values >>> x, y = y, x  Assignments can be chained >>> a = b = x = 2
  • 13. Mathematical Operators  Exercise: Find an Euclidian distance between (2, 3) and (10, 8)
  • 14. Mathematical Operators  Exercise: For a given temperature in celsius stored in variable ‘t_c’, get the Fahrenheit temperature in ‘t_f’ and display result. • Let t_c = 100 • ans = 212
  • 15. Checking Data Types  Exercise: What would be the data-type of? >>> a = 4/3 >>> type(a) >>> n = 4//3 >>> type(a) >>> num = ‘2080’ >>> type(num)
  • 16. Type Casting  Converting one data type to another data type.  We use int(), float(), str() >> # float to int >> gravity = 9.81 >> print(int(gravity))
  • 17. Type Casting  When we do arithmetic operations string numbers should be first converted to int or float otherwise it will return an error. >> #str to int or float >> num_str = '10.6‘ >> print('num_int', int(num_str)) >> print('num_float', float(num_str))
  • 19. Comparison Operators  In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. >> 2 == 2 >> 3.14 == 3.1416 >> print(123 == ‘123’) >> print(123 == int(‘123’)) >> a = ‘mango’ >> b = ‘orange’ >> a == b >> a < b What does this show?
  • 21. Logical Operators  Logical operators are used to combine conditional statements: >> 2 == 2 and 2 < 4 True >> print() >> >> a = ‘mango’ >> b = ‘orange’ >> a == b >> a < b What does this show?
  • 22. Conditionals  In python the key word if is used to check if a condition is true and to execute the block code. Remember the indentation after the colon. a = 10 if a > 3: print(a, “is greater than 3”)  if else a = 3 if a > 0: print(a, “is positive number”) else: print(a, “is negative”)
  • 23. Conditionals  if elif else a = 3 if a > 0: print(a, “is positive number”) elif a < 0: print(a, “is negative number”) else: print(a, “is zero”)
  • 24. Operators and Conditionals  Exercise:  How do you check if a number is between 5 and 10 inclusive? Note: Use if statement here >>> if condition_1 and condition_2: ... choice_1 >>> else: ... choice_2 >>>
  • 25. Operators and Conditionals  Exercise:  How do you check if a number is even or not using python? Note: Use if statement here >>> if condition: ... choice_1 >>> else: ... choice_2 >>>
  • 26. Program for the Day Calculate Electricity Bill (15A) KWh Minimum Charge Charge per KWh 0 to 20 50 4.00 21 to 30 75 6.50 31 to 50 75 8.00 51 to 100 100 9.50 101 to 250 125 9.50 250 above 175 11 Ans: 2330 for 250 units
  • 27. Loops  In programming we also do lots of repetitive tasks. In order to handle repetitive task programming languages use loops. Python programming language also provides the following types of two loops: • while loop • for loop
  • 28. While Loop count = 0 while count < 5: print(count) count = count + 1 #prints from 0 to 4
  • 29. for Loop # syntax for iterator in range(start, end, step): #loop statements for i in range(1,10,1): print(i)
  • 30. for Loop num_list = [1,2,3,4,5] for num in num_list: print(num) it_companies = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', ‘Amazon‘] for company in it_companies: print(company)
  • 31. Program for the Day Student Grading SEE and NEB
  • 32. Program for the Day Student Grading SEE and NEB  For a given students’ mark in percentage, display letter grade for each student. marks = 90 Your code should display “Outstanding”
  • 33. Program for the Day Student Grading SEE and NEB  For a list of students’ marks in percentage, display letter grade for each student. marks = [95, 42, 78, 45, 89, 90] Use for loop