Skip to content
Snippets Groups Projects
Commit d69b05ac authored by cprutean's avatar cprutean
Browse files

Update file CodeExamples.ipynb

parent 1b1b5f64
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:52c89cc7 tags:
# Code Examples
The code examples are grouped together along certain themes. They can all be accessed below:
- ## Conditionals
Set of examples to demonstrate conditional statements (if elif else).
Take these and work / modify them and explore what happens:
> [OneWayConditional](OneWayConditional.ipynb): Simple one way (if) conditional.
> [TwoWayConditional](TwoWayConditional.ipynb): Simple two way (if else) conditional.
> [RootTwo](RootTwo.ipynb): Simply math.sqrt(x)**2 = x test to show the dangers of using test on floats; also the solution.
> [ThreeWayConditional](ThreeWayConditional.ipynb): Basic if elfi else structure, look at this carefully and understand it.
> [ComplexQuadrant](ComplexQuadrant.ipynb): Determine the quadrant of a complex numbers with a conditional chain in a function with multiple return options.
> [InsideSphere](InsideSphere.ipynb): Two way conditional in function and main program to test if a point is within a sphere.
> [FunctionCall](FunctionCall.ipynb): Example with function calls if conditional tests, a bit tricky, but important concepts here.
- ## File
Set of examples for reading and writing to simple text file.
> [ReadTextFile](ReadTextFile.ipynb): Read a text file and print out again (discussed "\n" problem with print()).
> [WriteFile](WriteFile.ipynb): Writes a bit of text (and culture) to a file. (this write / overwrites "burns.txt").
> [RangeLooptoFile](RangeLooptoFile.ipynb): Write data to a file from a loop.
> [LineCount](LineCount.ipynb): Open a file and countv the number of lines (with error trap for wrong filename).
> [ImageShow](ImageShow.ipynb): Read and display an image file using Matplotlib.
Data supplied
> [burns.txt](burns.txt): A bit of culture !!!
> [cosdata.txt](cosdata.txt): Output from RangeLooptoFile.py
> [sample.txt](sample.txt): Data for [Checkpoint 4](../Checkpoints/Checkpoint4.ipynb).
> [stones.jpg](stones.jpg): Stones on Scottish beach.
- ## Format
Example Python programs to show formatted output.
> [FloatFormat](FloatFormat.ipynb): Example of formatting floats with .format()
> [IntegerFormat](IntegerFormat.ipynb): Example of specifying and printing int in various bases.
- ## Functions
Example Python programs to illustrate the simple use of functions.
> [QuadraticFunction](QuadraticFunction.ipynb): Function for quadratic and how to use it.
> [TemperatureConverter](TemperatureConverter.ipynb): Fahrenheit to / from Celsius functions (see in mini-lectures).
> [PlanckPlot](PlanckPlot.ipynb): Plot the Planck radiation cuurve (details of plotting in ***Plotting*** example section).
- ## Further Functions
This set contains some more advanced use of functions.
> [PointsInCircle](PointsInCircle.ipynb): Use of function to return two floats as a list, and also some more advanced Matplotlib to display scatter plots and annonate graphs.
> [FunctionPlot](FunctionPlot.ipynb): Passing a function as the argument to another function, also returning lists from functions.
> [ListofFunctions](ListofFunctions.ipynb): Show that functions can be held in a list and the list elements can be called as functions. Shows the flexibility of lists, but this is not good programming style.
> [FunctionFromCommand](FunctionFromCommand.ipynb): Show functions names being entered from command line and then called.
- ## Getting Started
This theme contains a series of simple starter Python programs, these being:
> [Hello](Hello.ipynb): Minimal Hello World program with single print.
> [ReadingandPrintingStrings](ReadingandPrintingStrings.ipynb): Read a string by input() and print it.
> [ReadingandPrintingStringsMain](ReadingandPrintingStringsMain.ipynb): Read a string by input() and print it using a main() structure.
> [ReadingandPrintingFloats](ReadingandPrintingFloats.ipynb): Read a single float and print it out as a string.
> [ReadingandFormatFloatsMain](ReadingandFormatFloatsMain.ipynb): Read a single float and print it out as a string using a main() structure.
> [ReadingandPrintingFloatsMain](ReadingandPrintingFloatsMain.ipynb): Read a single float and print it out as a string using a main() structure.
> [ReadingandFormatFloats](ReadingandFormatFloats.ipynb): Read float, form *10^6 and ^2, and print out.
> [ReadingandFormatFloatsMain](ReadingandFormatFloatsMain.ipynb): Read float, form *10^6 and ^2, and print out using a main() structure.
> [ReadingIntandFloat](ReadingIntandFloat.ipynb): Read in int and float, and perform some basic arithmetic and print.
> [ReadingIntandFloatMain](ReadingIntandFloatMain.ipynb): Read in int and float, and perform some basic arithmetic and print using a main() structure.
- ## Lists
Set of simple list example, there are more extensive examples on the use of lists in the section on [Loops](../CourseNotes/loops.ipynb).
> [MakeandAppendList](MakeandAppendList.ipynb): Simple example to make a list of integers and append an extra element.
> [AppendFunction](AppendFunction.ipynb): A general simple append function that works for any object that implements the "+" operator.
> [ExtractSublist](ExtractSublist.ipynb): Example of extracting a sublist and adding lists together.
> [SortFunction](SortFunction.ipynb): A conceptually more complex use of a function operating on a list, rather more complex operation (not really needed in this course).
- ## Loops
This theme contains example programs with simple loops.
> [RangeLoop.ipynb](RangeLoop.ipynb): Loop to print out theta, cos(theta).
> [RangeLooptoList](RangeLooptoList.ipynb): For loop to list of theta, cos(theta) and print.
> [WhileLooptoList](WhileLooptoList.ipynb): Alternative version of above using while loop.
> [GuessGame](GuessGame.ipynb): Simple interactive guess game to guess an int with while loop.
- ## Maths
Set of Python example programs illustrating basic mathematics and how to call functions from the math module.
> EvaluateQuadratic.py evaluates a a*x**2 + b*c + c quadtartic
> EvaluateSinCos.py converts angle from degrees to radians and evaluates
sin / cos functions.
> Cosine Rule.py Calculate side lengths and angles of a triangle
using cosine and sine rules.
> BasicComplex.py Basic use of complex, read complex, basic calcualtion
and display
> MultiplyByLogs.py demonestrates using log / exp to perform
multiplication and division.
> MultiplyByLogsNegativeFixed.by same as program above but with fix to
deal with negative numbers
(a bit more compicated)
> EvaluateInput.py example of using eval() to evalate a string to float() and complex().
This replicates the old Phyton 2 behaviour.
> ComplexImpedance.py Application of complex to calculate the complex
impedance of LRC circuit.
- MoreComplex
- Objects
- Plotting
- Scope
Index of all code examples:
- [AppendFunction](AppendFunction.ipynb)
- [ComplexQuadrant](ComplexQuadrant.ipynb)
- [CosPlot](CosPlot.ipynb)
- [Ellipse](Ellipse.ipynb)
- [ExtractSublist](ExtractSublist.ipynb)
- [FlightPlot](FlightPlot.ipynb)
- [FloatFormat](FloatFormat.ipynb)
- [FunctionCall](FunctionCall.ipynb)
- [FunctionFromCommand](FunctionFromCommand.ipynb)
- [FunctionPlot](FunctionPlot.ipynb)
- [GaussianNoisePlot](GaussianNoisePlot.ipynb)
- [GuessGame](GuessGame.ipynb)
- [Hello](Hello.ipynb)
- [ImageShow](ImageShow.ipynb)
- [InsideSphere](InsideSphere.ipynb)
- [IntegerFormat](IntegerFormat.ipynb)
- [LineCount](LineCount.ipynb)
- [MakeandAppendList](MakeandAppendList.ipynb)
- [OneWayConditional](OneWayConditional.ipynb)
- [PiExample](PiExample.ipynb)
- [PlanckPlot](PlanckPlot.ipynb)
- [PointsInCircle](PointsInCircle.ipynb)
- [PrintList](PrintList.ipynb)
- [QuadraticFunction](QuadraticFunction.ipynb)
- [QuadraticPlot](QuadraticPlot.ipynb)
- [RangeLoop.ipynb](RangeLoop.ipynb)
- [RangeLooptoFile](RangeLooptoFile.ipynb)
- [RangeLooptoList](RangeLooptoList.ipynb)
- [ReadScope](ReadScope.ipynb)
- [ReadTextFile](ReadTextFile.ipynb)
- [ReadingIntandFloat](ReadingIntandFloat.ipynb)
- [ReadingIntandFloatMain](ReadingIntandFloatMain.ipynb)
- [ReadingandFormatFloats](ReadingandFormatFloats.ipynb)
- [ReadingandFormatFloatsMain](ReadingandFormatFloatsMain.ipynb)
- [ReadingandPrintingFloats](ReadingandPrintingFloats.ipynb)
- [ReadingandPrintingFloatsMain](ReadingandPrintingFloatsMain.ipynb)
- [ReadingandPrintingStrings](ReadingandPrintingStrings.ipynb)
- [ReadingandPrintingStringsMain](ReadingandPrintingStringsMain.ipynb)
- [RootTwo](RootTwo.ipynb)
- [SimpleEllipse](SimpleEllipse.ipynb)
- [SortFunction](SortFunction.ipynb)
- [SphereVolume](SphereVolume.ipynb)
- [TemperatureConverter](TemperatureConverter.ipynb)
- [ThreeWayConditional](ThreeWayConditional.ipynb)
- [TwoWayConditional](TwoWayConditional.ipynb)
- [Vector](Vector.ipynb)
- [WhileLooptoList](WhileLooptoList.ipynb)
- [WriteFile](WriteFile.ipynb)
%% Cell type:code id:6b3360a6 tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment