You incorrectly transcribed the error message: the actual character shown is lower-case L, i.e. l, not a 1 like you showed. To avoid this mistake it is much better if you simply copy-and-paste the entire error message.
The reason is very simple: you refer to a function or variable l many times, but it is never defined. Here is the first instance:
After that line it occurs repeatedly, so perhaps you just need to assign some value to l at the start of your code.