Computer Science, asked by 19vs1010549, 1 day ago

Create a python list containing four integers. Replace the third and fourth item in
the list with the product of the last two items and print the list on the screen.

Answers

Answered by samarthkrv
6

Answer:

list = [1,2,3,4]

list[2] = list[2]*list[3]

list[3] = list[2]

print(list)

Explanation:

Answered by NehaKari
0

Answer:

Here's the Python code to create a list containing four integers and replace the third and fourth item with their product:

# Create a list of four integers

my_list = [2, 5, 7, 3]

# Replace third and fourth item with their product

product = my_list[-2] * my_list[-1]

my_list[-2:] = [product]

# Print the updated list

print(my_list)

The output of this code will be:

[2, 5, 21]

n this example, we create a list my_list containing four integers [2, 5, 7, 3]. We then calculate the product of the last two items in the list (7 * 3 = 21) and assign it to the variable product. We then use slicing to replace the third and fourth items in the list with the product, by assigning a new list containing the product to the slice my_list[-2:]. Finally, we print the updated list, which now contains the integers [2, 5, 21].

#SPJ2

Similar questions