SlideShare a Scribd company logo
1 of 42
Problem 1
Given the number of hours and minutes browsed, write a
program to calculate bill for Internet Browsing in a browsing
center. The conditions are given below.
(Assume that a user can only browser to maximum of 7 hours)
(a) 1 Hour Rs.50
(b) 1 minute Re. 1
(c) 5 Hours Rs. 200
Pseudocode
READ hours and minutes
SET amount = 0
IF hours >=5 then
CALCULATE amount as amount + 200
COMPUTE hours as hours – 5
END IF
COMPUTE amount as amount + hours * 50
COMPUTE amount as amount + minutes * 1
PRINT amount
Different patterns in Algorithm
Sequential
 Sequential structure executes the program in the order in
which they appear in the program
Selectional (conditional-branching)
 Selection structure control the flow of statement execution
based on some condition
Iterational (Loops)
 Iterational structures are used when part of the program is to
be executed several times
Selection pattern
• A selection control statement is a control
statement providing selective execution of
instructions.
• A selection control structure is a given set of
instructions and the selection control
statement(s) controlling their execution.
Control flow of decision making
If Statement
• An if statement is a selection control
statement based on the value of a given
Boolean expression.
The if statement in Python is
If statement Example use
If condition:
statements
statements
else:
statements
If grade >=70:
print(‘pass’)
else:
Print(‘fail’)
Indentation in Python
• One fairly unique aspect of Python is that the amount of
indentation of each program line is significant.
• In Python indentation is used to associate and
group statements
Selection pattern
Example 1: Write a program to find the average score of a student in
physics, chemistry and maths which help them to qualify for a
medical education or engineering education. If the average score
is greater than or equal to 70, the candidate is eligible for
scholarship and not eligible for scholarship otherwise
Algorithm:
Step 1 : Start
Step 2: Get the input marks for physcis,chemistry and maths
Step 3 : Accumulate all the marks and store it in Total
Step 4 : Divide Total by 3 and store it in Average
Step 5 : If the Average score is greater than or equal to 70; candidate qualified for
scholarship
Else not qualified for scholarship
Stop 6: Stop
Flowchart
Start
Accept phy,chem, maths
total=phy+che+maths
average=total/3
eligible for
scholarship
Stop
Is Total
>=98
Not eligible
for
scholarship
Y
N
Pseudo code:
begin
accept phy_mark,che_mark,math_mark
compute total = phy_mark +che_mark+math_mark
compute average=total/3
if (total >= 98 )
begin
display ‘ candidate eligible for scholarship’
end
else
begin
display ‘candidate not eligible for scholarship’
end
end
Python code : mark.py
phy_mark=97
che_mark=91
mat_mark=99
total_mark=phy_mark+che_mark+mat_mark
print(‘ candidate obtained ‘, total_mark)
if total_mark >= 98 :
print(‘candidate eligible for scholarship ')
else :
print(' candidate not eligible for scholarship ')
Nested if Statements
• There are often times
when selection among
more than two sets of
statements (suites) is
needed.
• For such situations, if
statements can be
nested, resulting in
multi-way selection.
Example1: Write a program to find the biggest
among three given number?
Algorithm:
Step1: Start
Step2: Get three input value namely a, b and c
Step3: Compare a with b, if a is greater than b
compare a with c and if a is bigger say a is bigger
else say c is bigger
Step 4: Compare b with c , if b is greater than c say
b is bigger else c is bigger
Step 5: Stop
Flowchart
Y
N
Y
N
Start
Accept a,b and c
display a
is bigger
Stop
Is
a>b
display b
is bigger
Is
a>c
Is
b>c
display c
is bigger
N
Y
Pseudo code:
read a, b and c
if (a > b)
if (a>c)
display ‘ a is greater’
else
display ‘ c is greater’
else
if (b>c)
display ‘ b is greater’
else
display ‘ c is greater’
Python code : big.py
a=15
b=6
c=7
if a>b:
if a>c:
print(" a is greater")
else:
print(" c is greater")
else:
if b>c:
print(" b is greater")
else:
print(" c is greater")
Else if Ladder
• if-else statements may be nested to achieve
multi-way selection
Example:
Example: Write a program to find out the gift amount to be given for the students
based on their entrance exam marks:
If mark>=90 then 10000
>=80 mark and <90 then 5000
>=70 mark and <80 then 2000
Else ‘no gift’
Algorithm :
Step1 : Start
Step2: input the entrance mark
Step 3: if mark greater than or equal to 90 say then amount is 10000
else if mark greater than or equal to 80 then gift amount is 5000
else if mark greater than or equal to 70 then gift amount is 2000
else say ‘no gift’
Step 4: Stop
Flowchart
Y
N
Start
input entrance
mark
display amount is
10000
Stop
Is
mark>=90
N
Y
Is
mark>=80
display amount is
5000
Is
mark>=70
display amount is
2000
Y
N
display no gift
Pseudo code:
read entrance_mark
if (entrance_mark >=90)
display('amount is 10000 ')
else
if(entrance_mark >=80)
display(' amount is 5000 ')
else
if(entrance_mark >=70)
display(' amount is 2000 ')
else
display(‘no gift')
Example 1: Python code
entrance_mark=75
if entrance_mark >=90:
print(' amount is 10000 ')
elif entrance_mark >=80:
print(' amount is 5000 ')
elif entrance_mark >=70:
print(‘amount is 2000 ')
else:
print(‘no gift')
Multiple Conditions
• Multiple conditions can be check in a ‘if’
statement using logical operators ‘and’ and
‘or’.
• Python code to print ‘excellent’ if mark1 and
mark2 is greater than or equal to 90, print
‘good’ if mark1 or mark2 is greater than or
equal to 90, print ‘need to improve’ if both
mark1 and mark2 are lesser than 90
if mark1>=90 and mark2 >= 90:
print(‘excellent’)
if mark1>=90 or mark2 >= 90:
print(‘good’)
else:
print(‘needs to improve’)
Exercise Problem
Write a python code to check whether a
given number of odd or even?
number = int(input('Enter Number'))
if(number%2==0):
print('even')
else:
print('odd')
Input Processing Output Solution
Alternative
Number Apply
modulus
operator for
the Number
Odd or Even Repeated
subtraction of
2 from
Number till the
Number
becomes less
than 2
READ Number
COMPUTE Remainder = Number modulus 2
if Remainder == 0 then
print ‘Number is even’
else
print ‘Number is odd’
Pseudocode
Exercise Problem
Write a python code to check whether a
given year is leap year or not?
A year is a leap year if it is divisible by 4 and
not divisible by 100 or if it is divisible by 400
Input Processing Output Solution
Alternative
Year Take modulus
of year with 4,
100 and 400
and then
check for
remainder
Leap year or
not
-
READ year
value1 = year modulus 4
value 2 = year modulus 100
value 3 = year modulus 400
if (value1==0 and value2!=0) or (value3 == 0)
print ‘leap year’
else
print ‘Not leap year’
Pseudocode
Leap year Program
year = int(input('Enter year'))
if(((year%4==0)and(year%100!=0))or(year%400 == 0)):
print('leap year')
else:
print('not leap year')
Exercise Problem
Write a python program to segregate student
based on their CGPA. The details are as
follows:
<=9 CGPA <=10 - outstanding
<=8 CGPA <9 - excellent
<=7 CGPA <8 - good
Input Processing Output Solution
Alternative
CGPA Comparison
of CGPA
Print grade -
READ CGPA
if CGPA >=9 and CGPA <=10 then
print ‘outstanding’
else if CGPA >=8 and CGPA <=9 then
print ‘excellent’
else if CGPA >=7 and CGPA <=8 then
print ‘good’
Pseudocode
Python Program
CGPA = int(input('enter CGPA'))
if((CGPA>=9) and (CGPA<=10)):
print('Outstanding')
elif((CGPA>=8)and(CGPA<=9)):
print('Excellent')
elif((CGPA>=7)and(CGPA<=8)):
print('Good')
Exercise Problem
Write a python code in finding the roots of a
quadratic equation of the form ax2+bx+c = 0?
Input Processing Output Solution
Alternative
a,b,c Find the value
of discriminant
Compute
roots based
on value of
discriminant
Roots of
quadratic
equation
READ a,b,c
COMPUTE discriminant = b*b – 4*a*c
if discrminant<0 then
roots are imaginary
else if discrminant==0
roots are real and equal
else:
roots are real and unequal
Pseudocode
Pseudocode
If roots are real and equal then
r1 = r2 = -b/2*a
else if roots are real and unequal:
r1 = (-b+sqrt(discrminant))/2*a
r2 = (-b-sqrt(discrminant))/2*a
else if roots are imaginary:
r1 = -b/2*a + (sqrt(abs(discrminant))/2*a)i
r2 = -b/2*a - (sqrt(abs(discrminant))/2*a)I
#print roots
import math
a = int(input('Enter value of a'))
b = int(input('Enter value of b'))
c = int(input('Enter value of c'))
#find the value of b2 - 4ac
discrminant = b**2 - 4*a*c
if (discrminant<0):
#roots are imaginary
nature_Of_Roots = 0
elif (discrminant==0):
#roots are real and equal
nature_Of_Roots = 1
else:
#roots are real and unequal
nature_Of_Roots = 2
print("dis is",discrminant)
if(discrminant==0):
r1 = r2 = -b/2*a
elif(discrminant>0):
r1 = (-b+math.sqrt(discrminant))/2*a
r2 = (-b-math.sqrt(discrminant))/2*a
else:
r1 = complex(-b/2*a,math.sqrt(abs(discrminant))/2*a)
r2 = complex(-b/2*a,-1*math.sqrt(abs(discrminant))/2*a)
#print roots
print(r1)
print(r2)

More Related Content

Similar to presentation_python_11_1569171345_375360.pptx

Copy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designCopy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designalish sha
 
CIS 115 Inspiring Innovation/tutorialrank.com
 CIS 115 Inspiring Innovation/tutorialrank.com CIS 115 Inspiring Innovation/tutorialrank.com
CIS 115 Inspiring Innovation/tutorialrank.comjonhson110
 
CIS 115 Effective Communication - tutorialrank.com
CIS 115  Effective Communication - tutorialrank.comCIS 115  Effective Communication - tutorialrank.com
CIS 115 Effective Communication - tutorialrank.comBartholomew18
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newLast7693
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newscottbrownnn
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlpankit_ppt
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab neweyavagal
 
Lecture#3 Algorithms and computing
Lecture#3 Algorithms and computingLecture#3 Algorithms and computing
Lecture#3 Algorithms and computingNUST Stuff
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingHemantha Kulathilake
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfjanakim15
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptMaiGaafar
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 

Similar to presentation_python_11_1569171345_375360.pptx (20)

python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 
Unit-I Algorithm.pptx
Unit-I Algorithm.pptxUnit-I Algorithm.pptx
Unit-I Algorithm.pptx
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Copy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designCopy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program design
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
 
CIS 115 Inspiring Innovation/tutorialrank.com
 CIS 115 Inspiring Innovation/tutorialrank.com CIS 115 Inspiring Innovation/tutorialrank.com
CIS 115 Inspiring Innovation/tutorialrank.com
 
CIS 115 Effective Communication - tutorialrank.com
CIS 115  Effective Communication - tutorialrank.comCIS 115  Effective Communication - tutorialrank.com
CIS 115 Effective Communication - tutorialrank.com
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlp
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Lecture#3 Algorithms and computing
Lecture#3 Algorithms and computingLecture#3 Algorithms and computing
Lecture#3 Algorithms and computing
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.ppt
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 

presentation_python_11_1569171345_375360.pptx

  • 1. Problem 1 Given the number of hours and minutes browsed, write a program to calculate bill for Internet Browsing in a browsing center. The conditions are given below. (Assume that a user can only browser to maximum of 7 hours) (a) 1 Hour Rs.50 (b) 1 minute Re. 1 (c) 5 Hours Rs. 200
  • 2. Pseudocode READ hours and minutes SET amount = 0 IF hours >=5 then CALCULATE amount as amount + 200 COMPUTE hours as hours – 5 END IF COMPUTE amount as amount + hours * 50 COMPUTE amount as amount + minutes * 1 PRINT amount
  • 3. Different patterns in Algorithm Sequential  Sequential structure executes the program in the order in which they appear in the program Selectional (conditional-branching)  Selection structure control the flow of statement execution based on some condition Iterational (Loops)  Iterational structures are used when part of the program is to be executed several times
  • 4. Selection pattern • A selection control statement is a control statement providing selective execution of instructions. • A selection control structure is a given set of instructions and the selection control statement(s) controlling their execution.
  • 5. Control flow of decision making
  • 6. If Statement • An if statement is a selection control statement based on the value of a given Boolean expression. The if statement in Python is If statement Example use If condition: statements statements else: statements If grade >=70: print(‘pass’) else: Print(‘fail’)
  • 7. Indentation in Python • One fairly unique aspect of Python is that the amount of indentation of each program line is significant. • In Python indentation is used to associate and group statements
  • 8. Selection pattern Example 1: Write a program to find the average score of a student in physics, chemistry and maths which help them to qualify for a medical education or engineering education. If the average score is greater than or equal to 70, the candidate is eligible for scholarship and not eligible for scholarship otherwise Algorithm: Step 1 : Start Step 2: Get the input marks for physcis,chemistry and maths Step 3 : Accumulate all the marks and store it in Total Step 4 : Divide Total by 3 and store it in Average Step 5 : If the Average score is greater than or equal to 70; candidate qualified for scholarship Else not qualified for scholarship Stop 6: Stop
  • 9. Flowchart Start Accept phy,chem, maths total=phy+che+maths average=total/3 eligible for scholarship Stop Is Total >=98 Not eligible for scholarship Y N
  • 10. Pseudo code: begin accept phy_mark,che_mark,math_mark compute total = phy_mark +che_mark+math_mark compute average=total/3 if (total >= 98 ) begin display ‘ candidate eligible for scholarship’ end else begin display ‘candidate not eligible for scholarship’ end end
  • 11. Python code : mark.py phy_mark=97 che_mark=91 mat_mark=99 total_mark=phy_mark+che_mark+mat_mark print(‘ candidate obtained ‘, total_mark) if total_mark >= 98 : print(‘candidate eligible for scholarship ') else : print(' candidate not eligible for scholarship ')
  • 12. Nested if Statements • There are often times when selection among more than two sets of statements (suites) is needed. • For such situations, if statements can be nested, resulting in multi-way selection.
  • 13. Example1: Write a program to find the biggest among three given number? Algorithm: Step1: Start Step2: Get three input value namely a, b and c Step3: Compare a with b, if a is greater than b compare a with c and if a is bigger say a is bigger else say c is bigger Step 4: Compare b with c , if b is greater than c say b is bigger else c is bigger Step 5: Stop
  • 14. Flowchart Y N Y N Start Accept a,b and c display a is bigger Stop Is a>b display b is bigger Is a>c Is b>c display c is bigger N Y
  • 15. Pseudo code: read a, b and c if (a > b) if (a>c) display ‘ a is greater’ else display ‘ c is greater’ else if (b>c) display ‘ b is greater’ else display ‘ c is greater’
  • 16. Python code : big.py a=15 b=6 c=7 if a>b: if a>c: print(" a is greater") else: print(" c is greater") else: if b>c: print(" b is greater") else: print(" c is greater")
  • 17.
  • 18. Else if Ladder • if-else statements may be nested to achieve multi-way selection Example:
  • 19. Example: Write a program to find out the gift amount to be given for the students based on their entrance exam marks: If mark>=90 then 10000 >=80 mark and <90 then 5000 >=70 mark and <80 then 2000 Else ‘no gift’ Algorithm : Step1 : Start Step2: input the entrance mark Step 3: if mark greater than or equal to 90 say then amount is 10000 else if mark greater than or equal to 80 then gift amount is 5000 else if mark greater than or equal to 70 then gift amount is 2000 else say ‘no gift’ Step 4: Stop
  • 20. Flowchart Y N Start input entrance mark display amount is 10000 Stop Is mark>=90 N Y Is mark>=80 display amount is 5000 Is mark>=70 display amount is 2000 Y N display no gift
  • 21. Pseudo code: read entrance_mark if (entrance_mark >=90) display('amount is 10000 ') else if(entrance_mark >=80) display(' amount is 5000 ') else if(entrance_mark >=70) display(' amount is 2000 ') else display(‘no gift')
  • 22. Example 1: Python code entrance_mark=75 if entrance_mark >=90: print(' amount is 10000 ') elif entrance_mark >=80: print(' amount is 5000 ') elif entrance_mark >=70: print(‘amount is 2000 ') else: print(‘no gift')
  • 23.
  • 24. Multiple Conditions • Multiple conditions can be check in a ‘if’ statement using logical operators ‘and’ and ‘or’. • Python code to print ‘excellent’ if mark1 and mark2 is greater than or equal to 90, print ‘good’ if mark1 or mark2 is greater than or equal to 90, print ‘need to improve’ if both mark1 and mark2 are lesser than 90
  • 25. if mark1>=90 and mark2 >= 90: print(‘excellent’) if mark1>=90 or mark2 >= 90: print(‘good’) else: print(‘needs to improve’)
  • 26. Exercise Problem Write a python code to check whether a given number of odd or even? number = int(input('Enter Number')) if(number%2==0): print('even') else: print('odd')
  • 27. Input Processing Output Solution Alternative Number Apply modulus operator for the Number Odd or Even Repeated subtraction of 2 from Number till the Number becomes less than 2
  • 28. READ Number COMPUTE Remainder = Number modulus 2 if Remainder == 0 then print ‘Number is even’ else print ‘Number is odd’ Pseudocode
  • 29. Exercise Problem Write a python code to check whether a given year is leap year or not? A year is a leap year if it is divisible by 4 and not divisible by 100 or if it is divisible by 400
  • 30. Input Processing Output Solution Alternative Year Take modulus of year with 4, 100 and 400 and then check for remainder Leap year or not -
  • 31. READ year value1 = year modulus 4 value 2 = year modulus 100 value 3 = year modulus 400 if (value1==0 and value2!=0) or (value3 == 0) print ‘leap year’ else print ‘Not leap year’ Pseudocode
  • 32. Leap year Program year = int(input('Enter year')) if(((year%4==0)and(year%100!=0))or(year%400 == 0)): print('leap year') else: print('not leap year')
  • 33. Exercise Problem Write a python program to segregate student based on their CGPA. The details are as follows: <=9 CGPA <=10 - outstanding <=8 CGPA <9 - excellent <=7 CGPA <8 - good
  • 34. Input Processing Output Solution Alternative CGPA Comparison of CGPA Print grade -
  • 35. READ CGPA if CGPA >=9 and CGPA <=10 then print ‘outstanding’ else if CGPA >=8 and CGPA <=9 then print ‘excellent’ else if CGPA >=7 and CGPA <=8 then print ‘good’ Pseudocode
  • 36. Python Program CGPA = int(input('enter CGPA')) if((CGPA>=9) and (CGPA<=10)): print('Outstanding') elif((CGPA>=8)and(CGPA<=9)): print('Excellent') elif((CGPA>=7)and(CGPA<=8)): print('Good')
  • 37. Exercise Problem Write a python code in finding the roots of a quadratic equation of the form ax2+bx+c = 0?
  • 38. Input Processing Output Solution Alternative a,b,c Find the value of discriminant Compute roots based on value of discriminant Roots of quadratic equation
  • 39. READ a,b,c COMPUTE discriminant = b*b – 4*a*c if discrminant<0 then roots are imaginary else if discrminant==0 roots are real and equal else: roots are real and unequal Pseudocode
  • 40. Pseudocode If roots are real and equal then r1 = r2 = -b/2*a else if roots are real and unequal: r1 = (-b+sqrt(discrminant))/2*a r2 = (-b-sqrt(discrminant))/2*a else if roots are imaginary: r1 = -b/2*a + (sqrt(abs(discrminant))/2*a)i r2 = -b/2*a - (sqrt(abs(discrminant))/2*a)I #print roots
  • 41. import math a = int(input('Enter value of a')) b = int(input('Enter value of b')) c = int(input('Enter value of c')) #find the value of b2 - 4ac discrminant = b**2 - 4*a*c if (discrminant<0): #roots are imaginary nature_Of_Roots = 0 elif (discrminant==0): #roots are real and equal nature_Of_Roots = 1 else: #roots are real and unequal nature_Of_Roots = 2 print("dis is",discrminant)
  • 42. if(discrminant==0): r1 = r2 = -b/2*a elif(discrminant>0): r1 = (-b+math.sqrt(discrminant))/2*a r2 = (-b-math.sqrt(discrminant))/2*a else: r1 = complex(-b/2*a,math.sqrt(abs(discrminant))/2*a) r2 = complex(-b/2*a,-1*math.sqrt(abs(discrminant))/2*a) #print roots print(r1) print(r2)