Ask Question
8 April, 03:33

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.

+4
Answers (1)
  1. 8 April, 07:05
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers