229k views
12 votes
Create a list called numbers containing the values from 1 through 15, then use slices to perform the following operations consecutively: a. Select number’s even integers. b. Replace the elements at indices 5 through 9 with 0s, then show the resulting list. c. Keep only the first five elements, then show the resulting list. d. Delete all the remaining elements by assigning to a slice. Show the resulting list.

User Lfergon
by
4.6k points

1 Answer

8 votes

Answer:

Kindly check explanation

Step-by-step explanation:

From python :

List containing values from 1 through 15:

my_list = list(range(1,16))

#creates a list of values from 1 to 15,(16 is excluded)

B.) select even integers :

for digits in my_list :

if digit%2 == 0;

print(digit)

# prints numbers in the list which does not leave a remainder when divided by .

C.)

for digits in my_list[4,9]:

my_digit[digits] = 0

my_digits

#Replaces the elements at indices 5 through 9 with 0s, then show the resulting list.

D.)

my_digits[:5]

#selects digits with index 0 up to 4

E.)

del my_digits[:5]

#DELETE elements in my digits starting from the fifth index

User NoComprende
by
4.3k points