SlideShare a Scribd company logo
PYTHON PROGRAMING
Python Programming Lab Program
Using Python 3.11
Instructor Name: Mr. Elias P.
For Automotive Engineering 4rth Year Students
Lab Objectives
To write, test, and debug simple Python programs.
To use operators in a python program.
To implement Python programs with conditionals.
To implement Python programs with loops.
Use functions for structuring Python programs.
Represent compound data using Python lists, tuples, and
dictionaries.
Lab Outcomes
Upon completion of the course, students will be able to:
Write, test, and debug simple Python programs.
Use operators in a python program.
Implement Python programs with conditionals.
Implement Python programs with loops.
Develop Python programs step-wise by defining functions and calling
them.
Use Python lists, tuples, dictionaries for representing compound data.
Download and Install Python Setup
Download the setup from the below link
http://python.org/downloads/
Installation steps
Step 1: Select Version of Python to Install.
Step 2: Download Python Executable Installer.
Step 3: Run Executable Installer.
Step 4: Verify Python Was Installed on Windows.
Step 5: Verify Pip Was Installed.
Step 6: Add Python Path to Environment Variables (Optional)
What is python
Python is a popular programming language. It was created in
1991 by Guido Van Rossum.
It is used for
Web development
Software development
Data analysis
Game development
Desktop application
Embedded application
Introduction to Python
Write python program to display hello world on the screen
i.e print("hello world")
Python First Program
Python Variables
Unlike other programming languages, Python has no command for
declaring variable.
A variable is created at the moment you first assign a value to it.
Example
X=5 # x is now type of int
Y= “Elias” # Y is now type of string
Print(x)
Print(y)
Variables do not need to be declared with any particular type and can even
change type after they have been set.
Python Variables Names
A variable can have a short name (like x and y) or amore descriptive name
like (age, fnam, lname, etc).
Rules for naming Python variables
A variable name must start with letter or underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and
underscores(A-Z, 0-9, and _)
A variable names are case sensitive (age, Age and AGE are three
different variables)
Continued
The python print statement is often used to output variables.
To combine both text and a variable, Python uses the + character:
Example
X=“Intereting.”
Print(“Python is “+ x)
The output will be
Python is Interesting.
Python Data Types
 Write a program to demonstrate different
number data types and string in Python.
INPUT
a=10; #Integer Datatype
b=11.5; #Float Datatype
c=2.05j; #Complex Number
xy="Automotive Engineering"
print("a is Type of",type(a)); #prints type of variable a
print("b is Type of",type(b)); #prints type of variable b
print("c is Type of",type(c)); #prints type of variable c
print("xy is Type of",type(xy)); #prints type of variable xy
OUTPUT
a is Type of <class ‘int’>
b is Type of <class ‘float’>
c is Type of <class ‘complex’>
xy is Type of <class ‘str’>
Reading input from Keyboard
Write a python program that reads input(your full name) from keyboard and
displays the result . Type the following code.
Input
fname=str(input("Please enter your first name :"))
lname=str(input("Please enter your Last name :"))
print("Your full name is" "n"+fname + " " +lname)
Output
Please enter your first name :ELIAS
Please enter your Last name :PETROS
Your full name is
ELIAS PETROS
ARTHIMETIC OPERATIONS
INPUT
Write a Python Program that accepts two numbers and make
d/t arithmetic on it
a = int(input ('Enter the first number:'))
b = int(input ('Enter the second number:'))
summ=a+b
mul=a*b
div=a/b
fdiv=a//b
modu=a%b
print("Addition of a and b is :" +str(summ))
print("Multiplication of a and b is :" +str(mul))
print("Division of a and b is :" +str(div))
print("Floar Division of a and b is :" +str(fdiv))
print("Modulo devision of a and b is :" +str(modu))
OUTPUT
Enter the first number:24
Enter the second number:13
Addition of a and b is :37
Multiplication of a and b is :312
Division of a and b is :1.8461538461538463
Floar Division of a and b is :1
Modulo devision of a and b is :11
Continued
Continued
Python String Methods and Functions
Python String Methods and Functions
#isalnum()
string= "bbc123"
print(string.isalnum())
#isalpha()(add 2)
string="campus"
print(string.isalpha())
#isdigit() (add a letter)
string="0123456789"
print(string.isdigit())
string="012345689"
print(string.isnumeric() )
string="Arba minch Sawla Campus"
print(string.istitle())
string="Arba Minch Technology Campus"
print(string.replace('Technology Campus','Univeristy'))
OUTPUT
True
True
True
True
False
Arba Minch Univeristy
Python String Methods and Functions
Python String Methods and Functions
Write a program to create, concatenate and
print a string and accessing sub-string from a
given string.
INPUT
s1=input("Enter first String : ");
s2=input("Enter second String : ");
print("First string is : ",s1);
print("Second string is : ",s2);
print("concatenations of two strings :",s1+s2);
print("Substring of given string :",s1[1:4]); # prints strin
g from 1 to 3 because array Indexing starts from 0 and
ends at n-1.
OUTPUT
Enter first String: COMPUTER
Enter second String: SCIENCE
First String is : COMPUTER
Second String is : SCIENCE
Concatenations of two strings :
COMPUTERSCIENCE
Substring of given string: OMP
Python Conditional (If ) Statement
Write a python program which accept one integer number
from keyboard then display the number when number is
greater than 0 using python if statement.
INPUT
a = int(input ('Enter the number:'))
if a > 0:
print (a, "is greater than 0")
OUTPUT
It displays a if the entered
number is greater than 0
Unless it cant display anything.
Python Conditional(If-Else) Statements
Write a python program which accept two integer
numbers from keyboard then display which number is
greater using python if-else statement.
INPUT
a = int(input ('Enter the first number:'))
b = int(input ('Enter the second number:'))
if a > b:
print (a, "is greater than ", b)
else:
print (b, "is greater than ",a)
OUTPUT
Enter the first number:12
Enter the second number:23
23 is greater than 12
Python Conditional(If-Elif- Else ) Statements
Write a python program which takes numbers from
keyboard then display the number is either positive,
negative or 0 using python if-elif-else statement.
INPUT
number=int(input("Please enter the number you want to check
?"))
if number>0:
print("The number you entered is positive")
elif number<0:
print("The number you entered is negative")
else :
print("The number you entered is zero")
OUTPUT
Please enter the number you
want to check ?32
The number you entered is
positive
Write a python sources code that accept students score then calculate the grade
of the score?
Note:- Score range and grade were provided as bellow
Score range: Grade :
90-100 ===>A
80-89 ===>B
70-79 ===>C
60-69 ===> D
Below 60 ===>F
Python Conditional Nested(If-Elif- Else ) Statements
Continued
INPUT
score=float(input("Please enter your score:"))
if score>=90:
print("Grade = A ")
elif score>=80:
print("Grade = B ")
elif score>=70:
print("Grade = C ")
elif score>=60:
print("Grade = D ")
else :
print("Grade = F ")
OUTPUT
Please enter your score:34
Grade = F

More Related Content

PPTX
Python for beginner, learn python from scratch.pptx
PPTX
Python (Data Analysis) cleaning and visualize
PPTX
Basics of Python Programming
PDF
Data Handling_XI- All details for cbse board grade 11
PPTX
lecture 2.pptx
PDF
Sessisgytcfgggggggggggggggggggggggggggggggg
PPTX
An Introduction To Python - Python Midterm Review
PDF
PPE-Module-1.2 PPE-Module-1.2 PPE-Module-1.2.pdf
Python for beginner, learn python from scratch.pptx
Python (Data Analysis) cleaning and visualize
Basics of Python Programming
Data Handling_XI- All details for cbse board grade 11
lecture 2.pptx
Sessisgytcfgggggggggggggggggggggggggggggggg
An Introduction To Python - Python Midterm Review
PPE-Module-1.2 PPE-Module-1.2 PPE-Module-1.2.pdf

Similar to Python.pptx (20)

PPTX
Chapter 1 Python Revision (1).pptx the royal ac acemy
PPTX
Introduction to python programming ( part-1)
PPTX
03 Variables - Chang.pptx
PPTX
Programming with python
PPTX
python_module_.................................................................
PDF
Python for data science by www.dmdiploma.com
PPTX
MODULE. .pptx
PPTX
Integrating Python with SQL (12345).pptx
PPTX
Presentation1 (1).pptx
PPTX
Review old Pygame made using python programming.pptx
PPTX
Python Conditional and Looping statements.pptx
PPTX
Python PPT2
PPTX
unit1.pptx for python programming CSE department
PPTX
PPT
introduction to python in english presentation file
PPTX
Learn about Python power point presentation
PDF
Introduction to Python - Jouda M Qamar.pdf
PPT
Python tutorialfeb152012
DOCX
Python in One Shot.docx
PDF
Python in one shot
Chapter 1 Python Revision (1).pptx the royal ac acemy
Introduction to python programming ( part-1)
03 Variables - Chang.pptx
Programming with python
python_module_.................................................................
Python for data science by www.dmdiploma.com
MODULE. .pptx
Integrating Python with SQL (12345).pptx
Presentation1 (1).pptx
Review old Pygame made using python programming.pptx
Python Conditional and Looping statements.pptx
Python PPT2
unit1.pptx for python programming CSE department
introduction to python in english presentation file
Learn about Python power point presentation
Introduction to Python - Jouda M Qamar.pdf
Python tutorialfeb152012
Python in One Shot.docx
Python in one shot
Ad

More from EliasPetros (12)

PPTX
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
PPTX
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
PPT
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
PPTX
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
PPTX
Database Akjljljlkjlkjkljlkjldiministration.pptx
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
PPTX
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PPTX
Chapter 08.pptx
PPT
chaptet 4 DC and CN.ppt
PPTX
5_6278455688045789623.pptx
PPT
chapter 1 DC and CN-1.ppt
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
Database Akjljljlkjlkjkljlkjldiministration.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Chapter 08.pptx
chaptet 4 DC and CN.ppt
5_6278455688045789623.pptx
chapter 1 DC and CN-1.ppt
Ad

Recently uploaded (20)

PDF
industrial engineering and safety system
PDF
Volvo EC300D L EC300DL excavator weight Manuals.pdf
PDF
Todays Technician Automotive Heating & Air Conditioning Classroom Manual and ...
PPT
ACCOMPLISHMENT REPOERTS AND FILE OF GRADE 12 2021.ppt
PPTX
Transmission system. Describe construction & working of varius automobile sys...
PDF
Honda Dealership SNS Evaluation pdf/ppts
PDF
Physics class 12thstep down transformer project.pdf
PPTX
IMMUNITY TYPES PPT.pptx very good , sufficient
PPTX
building_blocks.pptxdcsDVabdbzfbtydtyyjtj67
DOCX
lp of food hygiene.docxvvvvvvvvvvvvvvvvvvvvvvv
PDF
book-slidefsdljflsk fdslkfjslf sflgs.pdf
PDF
Volvo EC290C NL EC290CNL Excavator Service Repair Manual Instant Download.pdf
PPTX
Small Fleets, Big Change: Market Acceleration by Niki Okuk
PPTX
capstoneoooooooooooooooooooooooooooooooooo
PPT
Kaizen for Beginners and how to implement Kaizen
PPTX
Paediatric History & Clinical Examination.pptx
PDF
Volvo EC290C NL EC290CNL Hydraulic Excavator Specs Manual.pdf
PDF
3-REasdfghjkl;[poiunvnvncncn-Process.pdf
PDF
Delivers.ai: 2020–2026 Autonomous Journey
PPTX
UNIT-2(B) Organisavtional Appraisal.pptx
industrial engineering and safety system
Volvo EC300D L EC300DL excavator weight Manuals.pdf
Todays Technician Automotive Heating & Air Conditioning Classroom Manual and ...
ACCOMPLISHMENT REPOERTS AND FILE OF GRADE 12 2021.ppt
Transmission system. Describe construction & working of varius automobile sys...
Honda Dealership SNS Evaluation pdf/ppts
Physics class 12thstep down transformer project.pdf
IMMUNITY TYPES PPT.pptx very good , sufficient
building_blocks.pptxdcsDVabdbzfbtydtyyjtj67
lp of food hygiene.docxvvvvvvvvvvvvvvvvvvvvvvv
book-slidefsdljflsk fdslkfjslf sflgs.pdf
Volvo EC290C NL EC290CNL Excavator Service Repair Manual Instant Download.pdf
Small Fleets, Big Change: Market Acceleration by Niki Okuk
capstoneoooooooooooooooooooooooooooooooooo
Kaizen for Beginners and how to implement Kaizen
Paediatric History & Clinical Examination.pptx
Volvo EC290C NL EC290CNL Hydraulic Excavator Specs Manual.pdf
3-REasdfghjkl;[poiunvnvncncn-Process.pdf
Delivers.ai: 2020–2026 Autonomous Journey
UNIT-2(B) Organisavtional Appraisal.pptx

Python.pptx

  • 1. PYTHON PROGRAMING Python Programming Lab Program Using Python 3.11 Instructor Name: Mr. Elias P. For Automotive Engineering 4rth Year Students
  • 2. Lab Objectives To write, test, and debug simple Python programs. To use operators in a python program. To implement Python programs with conditionals. To implement Python programs with loops. Use functions for structuring Python programs. Represent compound data using Python lists, tuples, and dictionaries.
  • 3. Lab Outcomes Upon completion of the course, students will be able to: Write, test, and debug simple Python programs. Use operators in a python program. Implement Python programs with conditionals. Implement Python programs with loops. Develop Python programs step-wise by defining functions and calling them. Use Python lists, tuples, dictionaries for representing compound data.
  • 4. Download and Install Python Setup Download the setup from the below link http://python.org/downloads/ Installation steps Step 1: Select Version of Python to Install. Step 2: Download Python Executable Installer. Step 3: Run Executable Installer. Step 4: Verify Python Was Installed on Windows. Step 5: Verify Pip Was Installed. Step 6: Add Python Path to Environment Variables (Optional)
  • 5. What is python Python is a popular programming language. It was created in 1991 by Guido Van Rossum. It is used for Web development Software development Data analysis Game development Desktop application Embedded application Introduction to Python
  • 6. Write python program to display hello world on the screen i.e print("hello world") Python First Program
  • 7. Python Variables Unlike other programming languages, Python has no command for declaring variable. A variable is created at the moment you first assign a value to it. Example X=5 # x is now type of int Y= “Elias” # Y is now type of string Print(x) Print(y) Variables do not need to be declared with any particular type and can even change type after they have been set.
  • 8. Python Variables Names A variable can have a short name (like x and y) or amore descriptive name like (age, fnam, lname, etc). Rules for naming Python variables A variable name must start with letter or underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores(A-Z, 0-9, and _) A variable names are case sensitive (age, Age and AGE are three different variables)
  • 9. Continued The python print statement is often used to output variables. To combine both text and a variable, Python uses the + character: Example X=“Intereting.” Print(“Python is “+ x) The output will be Python is Interesting.
  • 10. Python Data Types  Write a program to demonstrate different number data types and string in Python. INPUT a=10; #Integer Datatype b=11.5; #Float Datatype c=2.05j; #Complex Number xy="Automotive Engineering" print("a is Type of",type(a)); #prints type of variable a print("b is Type of",type(b)); #prints type of variable b print("c is Type of",type(c)); #prints type of variable c print("xy is Type of",type(xy)); #prints type of variable xy OUTPUT a is Type of <class ‘int’> b is Type of <class ‘float’> c is Type of <class ‘complex’> xy is Type of <class ‘str’>
  • 11. Reading input from Keyboard Write a python program that reads input(your full name) from keyboard and displays the result . Type the following code. Input fname=str(input("Please enter your first name :")) lname=str(input("Please enter your Last name :")) print("Your full name is" "n"+fname + " " +lname) Output Please enter your first name :ELIAS Please enter your Last name :PETROS Your full name is ELIAS PETROS
  • 12. ARTHIMETIC OPERATIONS INPUT Write a Python Program that accepts two numbers and make d/t arithmetic on it a = int(input ('Enter the first number:')) b = int(input ('Enter the second number:')) summ=a+b mul=a*b div=a/b fdiv=a//b modu=a%b print("Addition of a and b is :" +str(summ)) print("Multiplication of a and b is :" +str(mul)) print("Division of a and b is :" +str(div)) print("Floar Division of a and b is :" +str(fdiv)) print("Modulo devision of a and b is :" +str(modu)) OUTPUT Enter the first number:24 Enter the second number:13 Addition of a and b is :37 Multiplication of a and b is :312 Division of a and b is :1.8461538461538463 Floar Division of a and b is :1 Modulo devision of a and b is :11
  • 15. Python String Methods and Functions
  • 16. Python String Methods and Functions #isalnum() string= "bbc123" print(string.isalnum()) #isalpha()(add 2) string="campus" print(string.isalpha()) #isdigit() (add a letter) string="0123456789" print(string.isdigit()) string="012345689" print(string.isnumeric() ) string="Arba minch Sawla Campus" print(string.istitle()) string="Arba Minch Technology Campus" print(string.replace('Technology Campus','Univeristy')) OUTPUT True True True True False Arba Minch Univeristy
  • 17. Python String Methods and Functions
  • 18. Python String Methods and Functions Write a program to create, concatenate and print a string and accessing sub-string from a given string. INPUT s1=input("Enter first String : "); s2=input("Enter second String : "); print("First string is : ",s1); print("Second string is : ",s2); print("concatenations of two strings :",s1+s2); print("Substring of given string :",s1[1:4]); # prints strin g from 1 to 3 because array Indexing starts from 0 and ends at n-1. OUTPUT Enter first String: COMPUTER Enter second String: SCIENCE First String is : COMPUTER Second String is : SCIENCE Concatenations of two strings : COMPUTERSCIENCE Substring of given string: OMP
  • 19. Python Conditional (If ) Statement Write a python program which accept one integer number from keyboard then display the number when number is greater than 0 using python if statement. INPUT a = int(input ('Enter the number:')) if a > 0: print (a, "is greater than 0") OUTPUT It displays a if the entered number is greater than 0 Unless it cant display anything.
  • 20. Python Conditional(If-Else) Statements Write a python program which accept two integer numbers from keyboard then display which number is greater using python if-else statement. INPUT a = int(input ('Enter the first number:')) b = int(input ('Enter the second number:')) if a > b: print (a, "is greater than ", b) else: print (b, "is greater than ",a) OUTPUT Enter the first number:12 Enter the second number:23 23 is greater than 12
  • 21. Python Conditional(If-Elif- Else ) Statements Write a python program which takes numbers from keyboard then display the number is either positive, negative or 0 using python if-elif-else statement. INPUT number=int(input("Please enter the number you want to check ?")) if number>0: print("The number you entered is positive") elif number<0: print("The number you entered is negative") else : print("The number you entered is zero") OUTPUT Please enter the number you want to check ?32 The number you entered is positive
  • 22. Write a python sources code that accept students score then calculate the grade of the score? Note:- Score range and grade were provided as bellow Score range: Grade : 90-100 ===>A 80-89 ===>B 70-79 ===>C 60-69 ===> D Below 60 ===>F Python Conditional Nested(If-Elif- Else ) Statements
  • 23. Continued INPUT score=float(input("Please enter your score:")) if score>=90: print("Grade = A ") elif score>=80: print("Grade = B ") elif score>=70: print("Grade = C ") elif score>=60: print("Grade = D ") else : print("Grade = F ") OUTPUT Please enter your score:34 Grade = F