Skip to content

Maahin11/Python-Programming-class---3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Python While Loop Examples

This Jupyter Notebook contains various examples demonstrating the use of while loops in Python. Each example illustrates different use cases, including summation, iteration, conditional checks, and list manipulation.

Examples Included

  1. Summation from 1 to 50:

    • A while loop is used to calculate the cumulative sum of numbers from 1 to 50.
    • The result is printed at each step.
  2. Print Numbers from 15 to 30:

    • A simple while loop prints numbers from 15 to 30.
  3. Summation from 50 to 100:

    • This example calculates the cumulative sum of numbers from 50 to 100 using a while loop.
    • The result is printed at each step.
  4. Print Even Numbers from 1 to 20:

    • A while loop is used to iterate through numbers from 1 to 20, printing only the even numbers.
  5. Factorial Calculation:

    • The user inputs a number, and the program calculates its factorial using a while loop.
  6. Sum of Digits:

    • The user inputs a number, and the program calculates the sum of its digits using a while loop.
  7. List Manipulation:

    • Various examples of list manipulation using while loops, including:
      • Accessing and modifying list elements.
      • Reversing a list.
      • Finding the maximum value in a list.
  8. Infinite Loop with Break and Continue:

    • Examples of using break and continue statements within an infinite while loop to control the flow of execution.

How to Use

  1. Run the Notebook:

    • Open the notebook in a Jupyter environment (e.g., Jupyter Notebook, JupyterLab, or Google Colab).
    • Run each cell sequentially to see the output of each example.
  2. Modify and Experiment:

    • Feel free to modify the code in each cell to experiment with different inputs and conditions.
    • For example, change the range of numbers or the conditions in the loops to see how the output changes.

Requirements

  • Python 3.x
  • Jupyter Notebook or any compatible environment (e.g., Google Colab)

Author

  • Mahin
  • Date: 06/11/2024

About

Python While Loop Examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published