diff --git a/CodeExamples/FunctionCall.ipynb b/CodeExamples/FunctionCall.ipynb index 7ccccce41d2bdbe6a896ba0885b9102609965f34..5ff99bb76793a17ae8ca0cbd882622113240e7bc 100644 --- a/CodeExamples/FunctionCall.ipynb +++ b/CodeExamples/FunctionCall.ipynb @@ -16,7 +16,7 @@ "outputs": [], "source": [ "\"\"\"\n", - " Example of calling functions within if satements.\n", + " Example of calling functions within if statements.\n", " Work through this carefully and understand why the funcions get called when they do.\n", "\"\"\"\n", "\n", @@ -27,27 +27,20 @@ "def FnTwo(): # Define a function that returns True\n", " print(\"Function Two Called\")\n", " return True\n", - "\n", - "def main():\n", - " \n", - " # Use the functions with an \"and\" \n", - " print(\"Result of call with `and' \")\n", - " if FnOne() and FnTwo():\n", - " print(\"Success\")\n", - " else:\n", - " print(\"Failure\")\n", - "\n", - " \n", - " # Use the functions with an \"or\"\n", - " print(\"\\n\\nResult of call with `or'\")\n", - " if FnOne() or FnTwo():\n", - " print(\"Success\")\n", - " else:\n", - " print(\"Failure\")\n", - "\n", - "\n", - "# execute the program\n", - "main()" + " \n", + "# Use the functions with an \"and\" \n", + "print(\"Result of call with `and' \")\n", + "if FnOne() and FnTwo():\n", + " print(\"Success\")\n", + "else:\n", + " print(\"Failure\")\n", + " \n", + "# Use the functions with an \"or\"\n", + "print(\"\\n\\nResult of call with `or'\")\n", + "if FnOne() or FnTwo():\n", + " print(\"Success\")\n", + "else:\n", + " print(\"Failure\")" ] } ], diff --git a/CodeExamples/FunctionFromCommand.ipynb b/CodeExamples/FunctionFromCommand.ipynb index c3d36e9332ee137e1af714fe3662cdcea2085638..c74510e8615da8d34ac3d25e9f02154bde776756 100644 --- a/CodeExamples/FunctionFromCommand.ipynb +++ b/CodeExamples/FunctionFromCommand.ipynb @@ -17,7 +17,7 @@ "source": [ "\"\"\"\n", " Example program to show that you read in a function name from the\n", - " command line and then ececute it\n", + " command line and then execute it\n", "\n", " Try with fnOne, fnTwo, it it also works for math.cos, math.sin, math.log etc\n", "\"\"\"\n", @@ -29,7 +29,7 @@ " \"\"\"\n", " Create a function\n", " \"\"\"\n", - " print(\"Funcion one called with y = \" + str(y))\n", + " print(\"Function one called with y = \" + str(y))\n", " return y # Just return the given vaue\n", "\n", "\n", @@ -37,22 +37,15 @@ " \"\"\"\n", " Create a second function\n", " \"\"\"\n", - " print(\"Funcion two called with y = \" + str(y))\n", + " print(\"Function two called with y = \" + str(y))\n", " return 2*y # Just return double the value\n", "\n", + "while True: # Keep in a loop\n", + " fn = eval(input(\"function : \")) # Read in function name NOTE: eval()\n", + " y = float(input(\"y value : \")) # Get a parameter value\n", "\n", - "def main():\n", - "\n", - " while True: # Keep in a loop\n", - " fn = eval(input(\"function : \")) # Read in functioon name NOTE: eval()\n", - " y = float(input(\"y value : \")) # Get a parameter value\n", - "\n", - " z = fn(y) # Call function read in\n", - " print(\"Value returned is : \" + str(z))\n", - "\n", - "\n", - "if __name__ == \"__main__\":\n", - " main()" + " z = fn(y) # Call function read in\n", + " print(\"Value returned is : \" + str(z))" ] } ], diff --git a/CodeExamples/FunctionPlot.ipynb b/CodeExamples/FunctionPlot.ipynb index 87dbb328034651b69171920c6bd0b10c27b3cb07..e7df5872d8d8bdb08649eaeee2dfd87d35619a0d 100644 --- a/CodeExamples/FunctionPlot.ipynb +++ b/CodeExamples/FunctionPlot.ipynb @@ -37,8 +37,7 @@ " x_data = []\n", " y_data = []\n", "\n", - " #\n", - " # Fill the x/y arrays using the supplied function.\n", + " # Fill the x/y arrays using the supplied function.\n", " while x <= max:\n", " x_data.append(x)\n", " y = fn(x)\n", @@ -46,22 +45,17 @@ " x += delta\n", " \n", " # Return the x and y lists\n", - " return x_data,y_data\n", + " return x_data, y_data\n", "\n", - "def main():\n", - " \n", - " # Get the x and y lists from the plot function\n", - " x_data , y_data = function_plot(1.0,4.0,100,examplefunction)\n", + "# Get the x and y lists from the plot function\n", + "x_data, y_data = function_plot(1.0,4.0,100,examplefunction)\n", "\n", - " # Plot them\n", - " plt.plot(x_data,y_data,\"g\") # Default plot in green\n", - " plt.title(\"Plot of quadratic\") # Add title/lables\n", - " plt.xlabel(\"x value\")\n", - " plt.ylabel(\"y value\")\n", - " plt.show() # show the actual plot\n", - "\n", - "\n", - "main()" + "# Plot them\n", + "plt.plot(x_data,y_data,\"g\") # Default plot in green\n", + "plt.title(\"Plot of quadratic\") # Add title/lables\n", + "plt.xlabel(\"x value\")\n", + "plt.ylabel(\"y value\")\n", + "plt.show() # show the actual plot" ] } ], diff --git a/CodeExamples/FunctionScope.ipynb b/CodeExamples/FunctionScope.ipynb index 64aef3def19b2e9d00975441474535411beba7b3..fe02d56765bcd2dd4847c81796e552672eb937ec 100644 --- a/CodeExamples/FunctionScope.ipynb +++ b/CodeExamples/FunctionScope.ipynb @@ -17,7 +17,7 @@ "source": [ "\"\"\" \n", " Here is an example of how NOT to use globals.\n", - " Look as this an try an find out what went wrong\n", + " Look as this and try and find out what went wrong\n", "\"\"\"\n", "\n", "\n", @@ -50,8 +50,6 @@ " # but it illustartes how dargerous globas can be...... this is real bug found in\n", " # a piece of student code (after a lot of searching)\n", "\n", - " \n", - "\n", "main()" ] } diff --git a/CodeExamples/GaussianNoisePlot.ipynb b/CodeExamples/GaussianNoisePlot.ipynb index 230021a9d8155124e40422ef77ee6ef63f4a0b1b..dead37a0156c3bede7cb17f54bb9933bf9b59175 100644 --- a/CodeExamples/GaussianNoisePlot.ipynb +++ b/CodeExamples/GaussianNoisePlot.ipynb @@ -23,24 +23,20 @@ "import random\n", "import matplotlib.pyplot as plt # Import the plot package as plt\n", "\n", - "def main():\n", + "point = 10000 # Number of points\n", + "gauss_data = [] # list to hold points\n", + "mean = 20.0 # mean of noise\n", + "sd = 2.0 # standard deviation of noise\n", "\n", - " point = 10000 # Number of points\n", - " gauss_data = [] # list to hold points\n", - " mean = 20.0 # mean of noise\n", - " sd = 2.0 # standard deviation of noise\n", "\n", + "while point >= 0: # Fill list with gauss randoms\n", + " gauss_data.append(random.gauss(mean,sd))\n", + " point -= 1\n", "\n", - " while point >= 0: # Fill list with gauss randoms\n", - " gauss_data.append(random.gauss(mean,sd))\n", - " point -= 1\n", - "\n", - " # Plot histogram with 40 bins and range of mean +/- 3sd\n", - " plt.hist(gauss_data, bins = 40, range = [mean - 3*sd , mean + 3*sd])\n", - " plt.title(\"Histogram of Gaussian Noise\")\n", - " plt.show()\n", - "\n", - "main()" + "# Plot histogram with 40 bins and range of mean +/- 3sd\n", + "plt.hist(gauss_data, bins = 40, range = [mean - 3*sd , mean + 3*sd])\n", + "plt.title(\"Histogram of Gaussian Noise\")\n", + "plt.show()" ] } ], diff --git a/CodeExamples/GuessGame.ipynb b/CodeExamples/GuessGame.ipynb index bbcec3a78df2bb462c5c43525405d035c9f427d0..5f67c565eaaae88be1b6dd3e50e1d4cf333076dc 100644 --- a/CodeExamples/GuessGame.ipynb +++ b/CodeExamples/GuessGame.ipynb @@ -23,29 +23,25 @@ "\n", "import random\n", "\n", - "def main():\n", - " correct = random.randint(1,9) # the randon correct value\n", - " print(\"Guess the number between 1 and 9\")\n", + "correct = random.randint(1,9) # the randon correct value\n", + "print(\"Guess the number between 1 and 9\")\n", "\n", - " number_of_tries = 0\n", + "number_of_tries = 0\n", "\n", - " while True: # Start of infinite loop\n", - " guess = int(input(\"Have a guess (give an int) : \"))\n", - " number_of_tries += 1\n", + "while True: # Start of infinite loop\n", + " guess = int(input(\"Have a guess (give an int) : \"))\n", + " number_of_tries += 1\n", "\n", - " if guess == correct: # Test if the guess is correct\n", - " print(\"You guessed right\")\n", - " break # If correct break the loop\n", - " else:\n", - " print(\"You guessed wrong.... have another go\")\n", - " # End of loop\n", + " if guess == correct: # Test if the guess is correct\n", + " print(\"You guessed right\")\n", + " break # If correct break the loop\n", + " else:\n", + " print(\"You guessed wrong.... have another go\")\n", + " # End of loop\n", "\n", "\n", - " # This is after loop.\n", - " print(\"You took \" + str(number_of_tries) + \" attempt to guess right\")\n", - "\n", - "\n", - "main()" + "# This is after loop.\n", + "print(\"You took \" + str(number_of_tries) + \" attempt to guess right\")" ] } ], diff --git a/CodeExamples/ImageShow.ipynb b/CodeExamples/ImageShow.ipynb index bfbb1fc6d65efe88f857e0e899925bb7df0b2d29..6ce8f604cce026b6ec1d7075ba5e8b43233a1bbe 100644 --- a/CodeExamples/ImageShow.ipynb +++ b/CodeExamples/ImageShow.ipynb @@ -25,14 +25,11 @@ "import matplotlib.pyplot as plt\n", "import matplotlib.image as img # Import image module\n", "\n", - "def main():\n", - " filename = str(input(\"Graphics file : \"))\n", + "filename = str(input(\"Graphics file : \"))\n", "\n", - " image = img.imread(filename) # Read the jpeg\n", - " plt.imshow(image) # render it in plot axis\n", - " plt.show() # display it\n", - "\n", - "main()" + "image = img.imread(filename) # Read the jpeg\n", + "plt.imshow(image) # render it in plot axis\n", + "plt.show() # display it" ] } ],