Loops

Syntax of a while loop statement:

while <Boolean expression>:
    <sequence of statements>

Calculate the sum of the number starting 1 to 100.

Syntax of a for loop statement:

for <variable> in <iterable object>:
    <sequence of statements>

Calculate the sum of the number starting 1 to 100.

Your Work

  1. Use a while loop to calculate the total of odd numbers from 1 to 21.
  2. Use a for loop to calculate the total of even numbers from 2 to 100.