I've got it working.
Unfortunately my university is tight and will only supply me with Arc 10.1, which doesn't have the Add Geometry Attributes tool. So I used the old fashioned 'Calculate geometry' function to add start and end z values to the attribute table. However, this was returning a z value of 0 for both the start and end points of every polyline.
After a bit of snooping I discovered that the z values for the layer had somehow reset to 0. Presumably during some other processing I'd done previously. So I re-extracted correct z values from a DEM of my study area. This got 'calculate geometry' to return the right z values and meant that my slope codes worked perfectly.
Here is the final code for percentage slope (using straight line length between the start and end points):
And here is the code I used to get slope in degrees from the percentage:
Thanks for all your help!