Day 08 - Python Homework

Practicing While Loops in Python

Today you will practice using while loops in Python. While loops repeat code until a condition becomes false. Work on the following problems step by step.

Remember: A while loop keeps running until its condition is no longer true. Don’t forget to update your loop variable!

Assignment 01: Counting Numbers

Use a while loop to print numbers in a sequence.

Objective:

Understand how to use a while loop to control repetition.

Instructions:

  • Print numbers from 1 to 20.
  • Print numbers in reverse order from 10 down to 1.

Assignment 02: Sum of Numbers

Use a while loop to calculate totals.

Objective:

Practice using a while loop to add numbers repeatedly.

Instructions:

  • Find the sum of numbers from 1 to 50.
  • Find the sum of even numbers between 1 and 50.

Assignment 03: User Controlled Loop

Use a while loop that keeps running until the user decides to stop.

Objective:

Learn how to use input to control when a while loop should exit.

Instructions:

  • Keep asking the user for numbers until they enter 0.
  • When they enter 0, stop the loop and display the sum of all entered numbers.

If you need help

Post in the group if you get stuck with:

Good luck and keep practicing!