Suppose I have this code:
dec = 7.1 + 6.6 + 27.2 + 66.5
jan = 7.1 + 6.6 + 27.2 + 66.5 + 65.7
feb = 7.1 + 6.6 + 27.2 + 66.5 + 65.7 + 69.7
And I want MMA to return:
dec: 107.4
jan: 173.1
feb: 242.8
I could accomplish this as follows:
dec = 7.1 + 6.6 + 27.2 + 66.5;
Print["dec: ", %]
jan = 7.1 + 6.6 + 27.2 + 66.5 + 65.7;
Print["jan: ", %]
feb = 7.1 + 6.6 + 27.2 + 66.5 + 65.7 + 69.7;
Print["feb: ", %]
But I have a long list of variables, and don't want to retype all their names. So I'd instead prefer to just copy and paste the same code in after each line, e.g., something like this:
dec = 7.1 + 6.6 + 27.2 + 66.5;
Print[SymbolName[%],": ", %]
jan = 7.1 + 6.6 + 27.2 + 66.5 + 65.7;
Print[SymbolName[%],": ", %]
feb = 7.1 + 6.6 + 27.2 + 66.5 + 65.7 + 69.7;
Print[SymbolName[%],": ", %]
Of course, the above doesn't work. But is there simple code that would?



foo = 10;HoldForm[In[#]] &[$Line - 1] /. DownValues[In]– Michael E2 Dec 11 '16 at 03:03