Why exactly is work a path function? This might be a stupid question, but why exactly is work a path function?
In school, my teacher said it’s because it depends on the path. She gave an example of walking up a mountain, and said the work you expend depends on the path you take (straight path up or circling up around the mountain). But isn’t the work expended just equal to $E= mgh?$
 A: Even if you walk on a flat ground, you spend some energy related to walking. This is because the energy you spend lifting your feet, is not returned to your body when the foot is lowered, but rather turned into heat.
When you walk up a mountain, you still need to spend similar energy just lifting and lowering your feet, but, in addition, with each step, you have to spend some energy or perform some work to raise the COG and, therefore, the potential energy of your body. 
This additional work, performed through the duration of the walk and contributing to the potential energy of your body, does not depend on the path you take - it is fully defined by the difference in elevation between the starting and the finishing points. 
So, your teacher is right saying that the total work you expend walking up a mountain depends on a path you take. It is not in conflict with the statement that the work needed to change the potential energy of your body does not.  
A: Work is path dependent only if non-conservative forces are involved. Lets take the example given by your teacher. It's true that in climbing a mountain work done by you will be $W=-mgh$ and this will be independent on the path you take to climb the mountain. We can observe that here work done is considered only against gravitational force which is a conservative force and we have neglected any friction that you encounter on the path. 
Now if you consider friction which is non-conservative force, work done will come out to be different for different paths. This is because value of friction depends on the path you take. 
A: As you pointed out mgh that is {gravitational force $\times$ your displacement above the ground} . Now you can say that in a dangerous way or steep way you will have to use a lot of energy and in a smooth or less steeper way you should lose less energy.  But the fact is that while calculating  gravitational work or potential energy change we just use $F. d$ or namely $mgh$ + the energy needed to overcome friction . But the energy in different paths may alter as they have different coefficient of friction and different lengths . The same goes for thermodynamical energy $W= PV$ is something which is path function.  Now the area of 2D P-V graph will give you the thermodynamic work. Now you know that a straight line will join two points of PV graph will give you less work than joining them hyperbolically . As you know the area alters for different constructions which join the two points of the P-V graph. So to get to a certain volume you can have different processes and their different works. So thermodynamic work is a path function. Here are the graphs 
