SlideShare a Scribd company logo
1 of 15
Loops in Python
Part ||
‫إعداد‬:
‫م‬.‫محمد‬ ‫علي‬
Objectives
 For loop statement with range
 While with is and is not
 If with for statements
 Break and continue
For loop with range
 As we saw at last video we can use range function with for loop and we
take an example for it
 Today we will take another examples:
 First example is the average of numbers from 1 to 10
 Second example is factor of number n!
Average for 1 to 10
 s=0
 for i in range(1,11):
 s=s+i
 su=s/10
 print(su)
Factor of number (n!)
 s=1
 for i in range(1,6):
 s=s*i
 print(s)
While with is and is not:
 As a Boolean operation we have the following operation in python
 is & not is
 We use is to make sure that two objects are same
 We use not is to make sure that two objects are not same
 We can use (int – string – float) as an objects
 Examples:
 >>> x=5
 >>> y=5
 >>> x is y
 True
 >>> x is not y
 False
 >>> a="ali"
 >>> b="Ali"
 >>> a is b
 False
 >>> a is not b
 True
 >>> c=3.5
 >>> d=3.4999999
 >>> c is d
 False
 >>> c is not d
 True
While with is and is not:
 To understood the usage of is and not is we will take the same example of
average of number and factor of number (n!) using while and (is) and (is
not)
 The program is written as following:
Average program
 s=1
 s1=11
 su=0
 while (s is not s1):
 su=s+su
 s+=1
 su=su/10
 print(su)
Factor of number (n!)
 s=1
 s1=6
 su=1
 while (s is not s1):
 su=su*s
 s+=1
 print(su)
If with for statements
 Also we can use if…else statement in for loop
 For example we can be sure that some number is in some range so we do
some thing for that
 Example:
s="t"
 s1="python"
 for i in s1:
 if s in s1:
 print("ok")
 else:
 print("some thing")
Break and continue
 The result for previous example is:
 ok
 ok
 ok
 ok
 ok
 ok
 That mean the (t) is in word (python) and repeat the result 6 times (length
of python world)
Break and continue
 What should we do to stop the loop when the program found (t)
 We must use break keyword
 break: stop the execution of loop for some reason
 The previous example will be like:
s="t"
 s1="python"
 for i in s1:
 if s in s1:
 print("ok")
 break
 else:
 print("some thing")
 And the result is:
 ok
Break and continue
 If we don’t want to print any thing if (t) in python what should we do
 We can use continue keyword
 Continue: to stop for a condition and continue after that
 Example: if we want to print 1 2 4 5 without 3
 We write:
for i in range(1,6):
 if i==3:
 continue
 print(i)
Break vs continue
 In the previous example if we use break instead of continue the result will
be like:
1
2
 Because break end all of loop but continue stop for condition and
continue over the loop

More Related Content

What's hot

Conditionalstatement
ConditionalstatementConditionalstatement
ConditionalstatementRaginiJain21
 
Nested Loops in C unit2.docx
Nested Loops in C unit2.docxNested Loops in C unit2.docx
Nested Loops in C unit2.docxJavvajiVenkat
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in PythonSumit Satam
 
Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaEdureka!
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5thConnex
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | LearnbayLearnbayin
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python ProgrammingManishJha237
 

What's hot (20)

Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
 
Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
 
Lesson 3 php numbers
Lesson 3  php numbersLesson 3  php numbers
Lesson 3 php numbers
 
Python programming
Python  programmingPython  programming
Python programming
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
 
Strings
StringsStrings
Strings
 
Function
FunctionFunction
Function
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
 
Nested Loops in C unit2.docx
Nested Loops in C unit2.docxNested Loops in C unit2.docx
Nested Loops in C unit2.docx
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
Defer, Panic, Recover
Defer, Panic, RecoverDefer, Panic, Recover
Defer, Panic, Recover
 
Composite types
Composite typesComposite types
Composite types
 
Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | Edureka
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5th
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | Learnbay
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
 

Similar to Fifth session

Workbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfWorkbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfDrDineshenScientist
 
Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc csKALAISELVI P
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxmonicafrancis71118
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docxmanohar25689
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSPYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSAniruddha Paul
 
Notes2
Notes2Notes2
Notes2hccit
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180Mahmoud Samir Fayed
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitionsaltwirqi
 

Similar to Fifth session (20)

Workbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfWorkbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdf
 
Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc cs
 
Chapter08.pptx
Chapter08.pptxChapter08.pptx
Chapter08.pptx
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
 
python program
python programpython program
python program
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docx
 
Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
Loops in Python.pptx
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSPYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMS
 
Python Math Concepts Book
Python Math Concepts BookPython Math Concepts Book
Python Math Concepts Book
 
Notes2
Notes2Notes2
Notes2
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180
 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 

More from AliMohammad155

#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...AliMohammad155
 
شرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLANشرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLANAliMohammad155
 
11th session classes diagrams
11th session classes diagrams11th session classes diagrams
11th session classes diagramsAliMohammad155
 
Static route and rip and ospf
Static route and rip and ospfStatic route and rip and ospf
Static route and rip and ospfAliMohammad155
 
Ninth session software engineering sequence diagram
Ninth session software engineering sequence diagramNinth session software engineering sequence diagram
Ninth session software engineering sequence diagramAliMohammad155
 
Routers and packet tracer
Routers and packet tracerRouters and packet tracer
Routers and packet tracerAliMohammad155
 
Viii session activity diagram
Viii session activity diagramViii session activity diagram
Viii session activity diagramAliMohammad155
 
Seventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleSeventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleAliMohammad155
 
Sixth session software engineering usecase diagrams
Sixth session software engineering usecase diagramsSixth session software engineering usecase diagrams
Sixth session software engineering usecase diagramsAliMohammad155
 
fifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnettingfifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnettingAliMohammad155
 
functional requirements and non functional requirements
functional requirements and non functional requirementsfunctional requirements and non functional requirements
functional requirements and non functional requirementsAliMohammad155
 
fourth session of basics in networks
fourth session of basics in networksfourth session of basics in networks
fourth session of basics in networksAliMohammad155
 
Fourth session software engineering
Fourth session software engineeringFourth session software engineering
Fourth session software engineeringAliMohammad155
 
third session of basics in networks
third session of basics in networksthird session of basics in networks
third session of basics in networksAliMohammad155
 
Third session software engineering
Third session software engineeringThird session software engineering
Third session software engineeringAliMohammad155
 
Second session Networking (Network topology)
Second session Networking (Network topology)Second session Networking (Network topology)
Second session Networking (Network topology)AliMohammad155
 
Second session software engineering algorithms
Second session software engineering   algorithmsSecond session software engineering   algorithms
Second session software engineering algorithmsAliMohammad155
 

More from AliMohammad155 (20)

#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
 
شرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLANشرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLAN
 
11th session classes diagrams
11th session classes diagrams11th session classes diagrams
11th session classes diagrams
 
10th session erd
10th session erd10th session erd
10th session erd
 
Static route and rip and ospf
Static route and rip and ospfStatic route and rip and ospf
Static route and rip and ospf
 
Ninth session software engineering sequence diagram
Ninth session software engineering sequence diagramNinth session software engineering sequence diagram
Ninth session software engineering sequence diagram
 
Routers and packet tracer
Routers and packet tracerRouters and packet tracer
Routers and packet tracer
 
Viii session activity diagram
Viii session activity diagramViii session activity diagram
Viii session activity diagram
 
OSI Model
OSI ModelOSI Model
OSI Model
 
Seventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleSeventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase example
 
Vlsm and flsm example
Vlsm and flsm exampleVlsm and flsm example
Vlsm and flsm example
 
Sixth session software engineering usecase diagrams
Sixth session software engineering usecase diagramsSixth session software engineering usecase diagrams
Sixth session software engineering usecase diagrams
 
fifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnettingfifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnetting
 
functional requirements and non functional requirements
functional requirements and non functional requirementsfunctional requirements and non functional requirements
functional requirements and non functional requirements
 
fourth session of basics in networks
fourth session of basics in networksfourth session of basics in networks
fourth session of basics in networks
 
Fourth session software engineering
Fourth session software engineeringFourth session software engineering
Fourth session software engineering
 
third session of basics in networks
third session of basics in networksthird session of basics in networks
third session of basics in networks
 
Third session software engineering
Third session software engineeringThird session software engineering
Third session software engineering
 
Second session Networking (Network topology)
Second session Networking (Network topology)Second session Networking (Network topology)
Second session Networking (Network topology)
 
Second session software engineering algorithms
Second session software engineering   algorithmsSecond session software engineering   algorithms
Second session software engineering algorithms
 

Recently uploaded

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Fifth session

  • 1. Loops in Python Part || ‫إعداد‬: ‫م‬.‫محمد‬ ‫علي‬
  • 2. Objectives  For loop statement with range  While with is and is not  If with for statements  Break and continue
  • 3. For loop with range  As we saw at last video we can use range function with for loop and we take an example for it  Today we will take another examples:  First example is the average of numbers from 1 to 10  Second example is factor of number n!
  • 4. Average for 1 to 10  s=0  for i in range(1,11):  s=s+i  su=s/10  print(su)
  • 5. Factor of number (n!)  s=1  for i in range(1,6):  s=s*i  print(s)
  • 6. While with is and is not:  As a Boolean operation we have the following operation in python  is & not is  We use is to make sure that two objects are same  We use not is to make sure that two objects are not same  We can use (int – string – float) as an objects  Examples:
  • 7.  >>> x=5  >>> y=5  >>> x is y  True  >>> x is not y  False  >>> a="ali"  >>> b="Ali"  >>> a is b  False  >>> a is not b  True  >>> c=3.5  >>> d=3.4999999  >>> c is d  False  >>> c is not d  True
  • 8. While with is and is not:  To understood the usage of is and not is we will take the same example of average of number and factor of number (n!) using while and (is) and (is not)  The program is written as following:
  • 9. Average program  s=1  s1=11  su=0  while (s is not s1):  su=s+su  s+=1  su=su/10  print(su)
  • 10. Factor of number (n!)  s=1  s1=6  su=1  while (s is not s1):  su=su*s  s+=1  print(su)
  • 11. If with for statements  Also we can use if…else statement in for loop  For example we can be sure that some number is in some range so we do some thing for that  Example: s="t"  s1="python"  for i in s1:  if s in s1:  print("ok")  else:  print("some thing")
  • 12. Break and continue  The result for previous example is:  ok  ok  ok  ok  ok  ok  That mean the (t) is in word (python) and repeat the result 6 times (length of python world)
  • 13. Break and continue  What should we do to stop the loop when the program found (t)  We must use break keyword  break: stop the execution of loop for some reason  The previous example will be like: s="t"  s1="python"  for i in s1:  if s in s1:  print("ok")  break  else:  print("some thing")  And the result is:  ok
  • 14. Break and continue  If we don’t want to print any thing if (t) in python what should we do  We can use continue keyword  Continue: to stop for a condition and continue after that  Example: if we want to print 1 2 4 5 without 3  We write: for i in range(1,6):  if i==3:  continue  print(i)
  • 15. Break vs continue  In the previous example if we use break instead of continue the result will be like: 1 2  Because break end all of loop but continue stop for condition and continue over the loop