1 / 19

Python Loops Tutorial | Python For Loop | While Loop Python | Python Training | Edureka

This Edureka "Python Loops" tutorial (Python Tutorial Blog: https://goo.gl/wd28Zr) will help you in understanding different types of loops used in Python. You will be learning how to implement all the loops in python practically. Below are the topics covered in this tutorial: <br><br>1) Why to use loops? <br>2) What are loops? <br>3) Types of loops in Python: While, For, Nested <br>4) Demo on each Python loop

EdurekaIN
Télécharger la présentation

Python Loops Tutorial | Python For Loop | While Loop Python | Python Training | Edureka

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EDUREKA PYTHON CERTIFICATION TRAINING Python Loops www.edureka.co/python

  2. Agenda ➢ Why to use loops ➢ What are loops ➢ Types of loops in Python ▪ While ▪ For ▪ Nested ➢ Summary www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  3. Why To Use Loops? www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  4. Why To Use Loops If a software developer develops a software module for payroll processing that needs to compute the salaries and the bonus of all the employees. Employee - 1 Salary Bonus Total Employee - 2 Software module for payroll processing Employee - 3 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  5. Why To Use Loops Manual Loops Start Start Start Start Logic to calculate the total salary Logic to calculate salary of Employee-1 Logic to calculate salary of Employee-2 Logic to calculate salary of Employee-3 Employee-1: Salary Bonus Total Employee-2: Salary Bonus Total Employee-3: Salary Bonus Total Employee-1: Salary Bonus Total Employee-2: Salary Bonus Total Employee-3: Salary Bonus Total www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  6. What are Loops? www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  7. What Are Loops  Loops allows the execution of a statement or a group of statement multiple times.  In order to enter the loop there are certain conditions defined in the beginning.  Once the condition becomes false the loop stops and the control moves out of the loop. Start Conditional Code If condition is true Infinite Finite Loops Condition If condition is false Exit www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  8. Loops In Python www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  9. While Loop While loops are known as indefinite or conditional loops. They will keep iterating until certain conditions are met. There is no guarantee ahead of time regarding how many times the loop will iterate. While Start Syntax: False While Condition? For True Body of the loop Nested Exit www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  10. While Loop Example A little guessing game While Let the correct answer be 13 For Input Number: 10 Number is too small Input Number: 15 Number is too large Nested Input Number: 13 Exit: Congratulations. You made it! www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  11. For Loop For loop is a Python loop which repeats a group of statements a specified number of times. The for loop provides a syntax where the following information is provided:  Boolean condition  The initial value of the counting variable  Incrementation of counting variable While Start If no more items in the sequence Item from sequence For Next item from sequence Execute Statement (s) Nested End www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  12. For Loop Example  Lets find factorial  Notice we know the number of iterations so for loop is a better option While n n-1 n-2 1 For 3! = 3(2)(1) 4! = 4(3)(2)(1) Example 5! = 5(4)(3)(2)(1) Nested Factorial = n(n-1)(n-2)…..1 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  13. Nested Loops Python programming language allows use of loop inside another loop. This is called Nested Loop. below is the syntax for the same: While Syntax: Syntax: For Nested www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  14. Nested Loop Example Lets code a program in Python that effectively simulates a bank ATM. While Check balance Make a withdrawal For Enter the 4-digit pin Pay in Return card Nested www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  15. Nested Loop Example  Lets write a code to print the Pythagorean numbers.  Three integers satisfying a2+b2=c2are called Pythagorean numbers a2 c2 While b2 Enter the maximum number: 20 For 3 4 5 5 12 13 6 8 10 8 15 17 9 12 15 12 16 20 Pythagorean numbers between 1-20 Nested www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  16. Nested Loop Example Using a for loop inside while loop While Bulk reservation: Name: Age: Sex: For Nested www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  17. Agenda Types of loops What are loops Why loops Nested loop While loop For loop www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  18. Thank You … Questions/Queries/Feedback www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

More Related