Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

ICW: Loops

Complete the following exercises by:

• Trying each one by yourself, adding your answers directly to this document. For
questions requiring code, you may provide pseudocode or executable code written
in Google Colab.

• Discussing the questions with your team and agreeing on the best answer and
editing your answer as needed.

• Submit your own completed assignment to its Canvas submission folder.

1. Write a while loop in pseudocode that sums all the numbers from 1 to 5.

2. Write a for loop sums all the numbers from 1 to 5.

3. Write a loop of your choice that sums only the even numbers from 1-10.

4. Write a loop that sums all the numbers from 1 to n, where “n” is a value given to
you by the user.

5. Write a loop that sums all the numbers from n down to 1, where “n” is a value
given to you by the user. You may assume n > 1.

6. Write a loop that calculates n! (n factorial, ex: 4! = 1x2x3x4) where “n” is a value
given to you by the user. You may assume n > 0.

7. Write a loop that sums all the numbers from m to n, where “m” and “n” are both
user given values. You may assume m>n.

1 6
3 4
.

. .

B .

2 .
7 .

You might also like