Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. For each of the following lists below, what should the value for s, e, and i

ID: 3665358 • Letter: 3

Question

3. For each of the following lists below, what should the value for s, e, and i be in list(range(s , e , i ) ) to give the corresponding list if you type it at the shell

: a. [-7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15]

b. [0, 3, 6, 9, 12, 15, 18, 21]

c. [5, 3, 1, -1, -3, -5, -7, -9]

d. [1, 3, 5, 11, 23]

4. For the following question, be sure to do import random at the shell first.

a. Give a Python statement for generating a random number between 50 and 501, inclusive.

b. Give a Python statement for selecting at random an element from the list [2, 4, 17, -1, 'car', 90, 'me', 99.50, 10000].

Explanation / Answer

a)

it will be

range (-7,15,2) //range requires(start,end,increment)

b

range(0,21,3)

c)

range(5,-9,-2)

d)

cannot be done with range. no such common difference

4

a)

working python code:

from random import randint
print(randint(50,501))

b)

working python code:

import random

mylist = [2, 4, 17, -1, 'car', 90, 'me', 99.50, 10000]
print(random.choice(mylist))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote