Ask Question
26 February, 10:09

Assume that lo and hi each are associated with an integer 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.

+4
Answers (1)
  1. 26 February, 12:25
    0
    The following are the program in the Python Programming Language

    #declare a variable and initialize to 'lo'

    i=lo

    #declare a variable and initialize to '0'

    result=0

    #set a while loop that iterates from 'hi' to 'lo'

    while (i<=hi):

    #Then, add i with result and store it in result.

    result=result+i

    #increament in the variable 'i' by 1

    i+=1

    Explanation:

    The following are the description of the program.

    Firstly, set the two variables that are 'i' and 'result', then, initialize in these variables to the variable 'lo' and '0'. Set the while loop statement that iterates from the variable 'i' and stops at the variable 'hi'. Finally, perform the addition with the variables 'result' and 'i' and store them in the variable 'result'. Then, increment in the variable 'i' by 1.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Assume that lo and hi each are associated with an integer and that result refers to 0. Write a while loop that adds the integers from lo up ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers