114k views
1 vote
Given that k and j each refer to a non-negative int and that play_list has been defined to be a list with at least j elements, write an expression that evaluates to a new list containing all the elements from the one at index k through the one at index j-1 of list play_list . Do not modify play_list .

User Hectorct
by
5.6k points

1 Answer

6 votes

Answer:

Following are the program in the Python Programming Language

#list type variable

play_list = [10,20,30,40,50,60,70,80]

k=3 #integer type variable

j=len(play_list) #integer type variable

new_list=play_list[k:j] #solution is here

print("play_list: ",play_list) #print variable play_list

print("new_list: ",new_list) #print variable new_list

Output:

play_list: [10, 20, 30, 40, 50, 60, 70, 80]

new_list: [40, 50, 60, 70, 80]

Step-by-step explanation:

Here, we set the list type variable "play_list" and assign elements in it is [10,20,30,40,50,60,70,80] then, we set an integer type variable "k" and assign value is 3.

  • Then, we set an integer type variable "j" and assign the length of the variable "play_list" in it.
  • Then, set the list type variable "new_list" and assign the elements of the variable "play_list" after applying slicing on it.
  • Finally, print the variable "play_list" and the variable "new_list".
User Ova
by
5.5k points