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))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.