Write a Python function fun3(e) to update a list of numbers e such that the first and last elements have been exchanged. The function needs to also return multiplication of elements of e. You should assume that the list e has at least 2 elements.Example:

>>>lst = [4, 1, 2, -1]




Answer 1


Here is code in Python:

#function to swap first and last element of the list

#and calculate product of all elements of list

def fun3(e):

   product = 1

   temp = e[0]

   e[0] = e[-1]

   e[-1] = temp

   for a in e:

       product *= a

   return product

#create a list

inp_lst = [4, 1, 2, -1]

#call the fun3() with parameter inp_lst

print("product of all elements of list is: ",fun3(inp_lst))

#print the list after swapping

print("list after swapping first and last element: ",inp_lst)


Create a list "inp_lst" and initialize it with [4,1,2,-1]. In the function fun3() pass a list parameter "e". create a variable "product" to calculate the product of all elements.Also create a temporary variable to swap the first and last element of the list.


product of all elements of list is:  -8                                                                                        

list after swaping first and last element:  [-1, 1, 2, 4]

Related Questions

Consider a demand-paging system in which processes are performing sequential data accesses with the following time-measured utilizations: CPU utilization 20% Paging disk 98% Other I/O devices 10% For each of the following, indicate yes or no to say whether or not it will (or is likely to) improve CPU utilization:a. Install a faster CPU b. Install a bigger paging diskc. Increase the degree of multiprogramming d. Decrease the degree of multiprogramming e. Install more main memory f. Install a faster hard diskg. Increase the page size
A(n) _____ is a harmful program that resides in the active memory of the computer and duplicates itself.WormVirusKeyloggerTimebomb
Initialize a list. ACTIVITY Initialize the list short.names with strings 'Gus', Bob, and 'Ann'. Sample output for the given program Gus Bob Ann 1 short_names- Your solution goes here 2 # print names 4 print(short_names[0])
Create a Produceclass that hasan instance variable of type Stringfor the name, appropriate constructors, appropriate accessor and mutator methods, and a public toString() method. Then create a Fruitand a Vegetableclass that are derived from Produce. These classes should have constructors that take the nameas a Stringand invoke the appropriate constructor from the base class to set the name.Also, they should override toStringmethod to display the nameof the produce and its type. For instance, Mangois a Fruitand Caulifloweris a Vegetable. Finally, create a class called TruckOfProducethat will keep track of the boxes of Vegetablesand Fruitsadded in to the truck. This class should use an array of Produceto store both Vegetableand Fruitobjects.
Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for (i = 0; i <99 ; i++) a[i] = a[a[i]];

What is the output, if userVal is 5? int x; x = 100; if (userVal != 0) { int tmpVal; tmpVal = x / userVal; System.out.print(tmpVal); }



The output is 20


This line divides the value of x by userVal

tmpVal = x / userVal;


tmpVal = 100/5

tmpVal = 20

This line then prints the value of tmpVal


i.e 20

Hence, The output is 20

Final answer:

The provided Java code checks if the variable userVal does not equal 0. As this is the case when userVal is 5, another variable tmpVal is assigned the value of another variable x (which is 100) divided by userVal. Hence, the output of the code would be 20.


In the given piece of code, the variable userVal is assigned a value of 5. The program also contains a variable x which is assigned a value of 100. An if statement checks whether userVal does not equal 0 - since 5 != 0, the condition is true. A new variable tmpVal is then declared and assigned the value of x divided by userVal, so tmpVal equals 100 / 5, which is 20. So, the output of this code when userVal is 5 would be 20.

Learn more about Java Programming here:



Which of these is outside the scope of an art director's responsibility?



Establishing Tight deadlines for a rush job.


The time taken for a rush job has nothing to do with the art director because it has nothing to do with art. Also rush jobs already call for tight deadlines so technically the deadline is already established.

Answer: cropping a photograph for the sake of space

Explanation: edge 22

What are the different options in a page layout feature ? Select three options



Half Center Right Left, theres four


Which of the following tools is specifically designed to test the dc voltage on a hard disk drive



A power supply tester is specifically designed to test DC voltage on most connectors coming from a PC power supply. A multimeter measures electrical properties such as voltage, amps, and resistance.

Population Growth The world population reached 7 billion people on October 21, 2011, and was growing at the rate of 1.1% each year. Assuming that the population
continues to grow at the same rate, approximately when will the population reach
8 billion? using python


Hope it this helps.

How many rules are contained in the css code?


I strongly agree that B is the answer