When is it useful to include the code in a thesis? I am writing my master of science thesis and I am not sure whether I should add some of the code I have written: they are not proper programs, but more like input files to be fed to a commercial program (Nastran) very popular in my field.

My concerns are related to the fact that I am not making any discovery, just applying the things I have learned reading the manual. Still, I feel the code will make the effort I put into the thesis to also learn this language clearer.
Making your code available along with your thesis can be very helpful to other researchers who are trying to reproduce your results.  I'd encourage you to do this.  

However, you should not simply insert a printout of your code into the text of the thesis, since that will make it difficult (practically impossible) for someone to use the code that they obtain from a printed copy of the thesis or even a .PDF of the thesis.  Rather, you should put the code into some online repository (such as e.g. github) so that others can download the code from the web.