QuestionAugust 10, 2025

Write the code using a while loop that finds the average of all the integers between 0-100

Write the code using a while loop that finds the average of all the integers between 0-100
Write the code using a while loop that finds the average of all the integers between 0-100

Solution
4.1(208 votes)

Answer

The average is 50.0 Explanation 1. Initialize variables Set `sum` to 0 and `count` to 0 for tracking the sum and count of numbers. 2. Implement while loop Use a while loop to iterate from 0 to 100, adding each number to `sum` and incrementing `count`. 3. Calculate average Divide `sum` by `count` to find the average. ```python sum = 0 count = 0 number = 0 while number <= 100: sum += number count += 1 number += 1 average = sum / count ```

Explanation

1. Initialize variables<br /> Set `sum` to 0 and `count` to 0 for tracking the sum and count of numbers.<br />2. Implement while loop<br /> Use a while loop to iterate from 0 to 100, adding each number to `sum` and incrementing `count`.<br />3. Calculate average<br /> Divide `sum` by `count` to find the average.<br /><br />```python<br />sum = 0<br />count = 0<br />number = 0<br /><br />while number <= 100:<br /> sum += number<br /> count += 1<br /> number += 1<br /><br />average = sum / count<br />```
Click to rate:

Similar Questions