Ask 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 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.

+2
Answers (1)
  1. 16 July, 15:09
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers