Ask Question
24 March, 16:03

Write a Python program to do the following:

(a) Use the range function to generate this sequence of integers: 5, 9, 13, 17 and 21. Save the numbers in a list. Display the list.

(b) Use a for loop to display each element in a separate line.

(c) Use the range function to generate this sequence of integers: 26, 19, 12 and 5. Save the numbers in a list. Display the list.

(d) Use a for loop to calculate the total of the elements in the second list. Display the total.

+1
Answers (1)
  1. 24 March, 17:09
    0
    (a) the range function has parameters as range (start, stop, step). Since our sequence starts at 5, stops at 21 prior to 22 and has a step side of 4

    L = range (5, 22, 4)

    (b)

    for e in L:

    print (e)

    (c) Since our sequence starts at 26, stops at 5 prior to 4 and has a step side of 7 negatively

    L2 = range (26, 4, - 7)

    (d) we can set up a total variable initially equals to 0. The add it to each element of L2 in the loop:

    total = 0

    for e in L2:

    total + = e

    print (total)
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a Python program to do the following: (a) Use the range function to generate this sequence of integers: 5, 9, 13, 17 and 21. Save the ...” 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