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

+2
Answers (1)
  1. 9 May, 22:53
    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?
Find 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 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