Laboratory 1: Getting startedPrerequisits: functions, import statements Contents Training preparations
This provides us a ''clean'' IPython interpreter session (within Spyder). You should carry out these steps before every laboratory. You now have an IPython interpreter available and are encouraged to carry out basic mathematical operations at the iPython prompt (In [?]:). PrerequisitesYou should know how to compute simple expressions such as
You will need some of these expressions below, and you should be familiar with using the Python Shell to evaluate Python expressions. You should know how to use a Python development environment. Assuming you use Spyder, you should know how to
If necessary, go through the exercise First steps executing Python programs interactively which explains how to do this. Worked example
Python prompt notationAlthough we expect that you use IPython for these exercises, we will initially also provide examples for the interaction with the Python prompt with >>> as displayed by the normal Python console instead of In [3]: as displayed by the IPython console: the number 3 here is meaningless as it only counts the number of inputs is that particular session. We write the example above therefore as: >>> average(10, 20) 15.0 >>> average(10, 4) 7.0 >>> help(average) Help on function average in module __main__: average(a, b) Given parameters a and b, compute and return the arithmetic mean of a and b. Equivalent IPython interaction: In [ ]: average(10, 20) Out[ ]: 15.0 In [ ]: average(10, 4) Out[ ]: 7.0 In [ ]: help(average) Help on function average in module __main__: average(a, b) Given parameters a and b, compute and return the arithmetic mean of a and b. Python and IPython console -- what is the difference?We also note that we will refer to the IPython console losely as the Python shell or Python console. In terms of the programming language, the IPython and Python shell can process the same command set. The IPython shell is only more powerful in providing tools that help us to write and debug code efficiently. Laboratory 1 trainingNow, it is your turn. Please define the following functions in the file training1.py and make sure they behave as expected. You also should document them in a way similar to the average function.
Submit your fileFor every function try to check carefully that your implementation is correct. The tab Testing tips provides some suggestions in form of a short checklist. Once you have gone through the checklist and think your functions are implemented correctly, please send an email to the coursework submission robot python4computing@gmail.com with subject training 1 and attach the training1.py file. You should soon get a a confirmation of the submission, and slightly later a report containing feedback through an automated analysis of your code. If the automated analysis says that some test failed, you can change your code and re-submit training1.py by emailing again to the same address. You can repeat this as often as you want. We urge you to improve and re-submit your work until you pass all tests. Ask the demonstrators for advice to interpret the error messages you may have received in your feedback email if tests have failed. While the work in this laboratory is not assessed, it is a crucial preparation for the assessment of later laboratory sessions and the class room tests. Assessment of lab workIn future labs, there will be often be a training component and an assessed component. For the training, you can submit your work as often as you like and this will not be assessed. It is, however, crucial preparation and practice for the assessed parts (and also the exam). For the assessed part, you can submit your work only once and points will be awarded depending on how many functions you have implemented correctly. Last updated: 2016-10-30 at 12:17 |
|