First Question:
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 .
This is what I have:
i = 0
while lo < hi:
result = i
i += 1
lo += 1
if lo == hi:
result = 0
For some reason... this doesn't work.
Second Question:
An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ... , the distance is 2 while in the sequence 6, 12, 18, 24, ... , the distance is 6.
Given the positive integer distance and the integers m and n , create a list consisting of the arithmetic progression between (and including) m and n with a distance of distance (if m > n, the list should be empty.) For example, if distance is 2, m is 5, and n is 12, the list would be [5, 7, 9, 11] .
Associate the list with the variable arith_prog .
What I have:
arith_prog = []
i = 0
if m > n:
[]
while i <= n:
arith_prog[::distance]
arith_prog.append(i)
i += distance
Also something wrong... thanks for the help.