Ask Question
16 December, 17:59

In this exercise, use the following variables : i, lo, hi, and result. Assume that lo and hi each are associated with an int and that result refers to 0.

Write a while loop that adds the integers from lo up through hi (inclusive), and associates the sum with result.

Your code should not change the values associated with lo and hi. Also, just use these variables : i, lo, hi, and result.

+1
Answers (1)
  1. 16 December, 21:42
    0
    result = 0

    i = lo

    while i < = hi:

    result = result + i

    i + = 1

    Explanation:

    Initialize the result as 0 to hold the summation value.

    Since we are asked not to change the value of lo and hi, our loop control variable is i and initially it starts from lo.

    Since we are asked to add the number from lo to hi, while loop condition checks it.

    While the condition satisfies (during each iteration), the value of i is added to the result and the value of i is incremented by one.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “In this exercise, use the following variables : i, lo, hi, and result. Assume that lo and hi each are associated with an int and that ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers