From 55224910ce5c20bcfe82074eefd94543e16e02e9 Mon Sep 17 00:00:00 2001
From: cprutean <cip.pruteanu@ed.ac.uk>
Date: Fri, 26 Jul 2024 13:03:18 +0100
Subject: [PATCH] Update 7 files

- /CodeExamples/FunctionCall.ipynb
- /CodeExamples/FunctionFromCommand.ipynb
- /CodeExamples/FunctionPlot.ipynb
- /CodeExamples/FunctionScope.ipynb
- /CodeExamples/GaussianNoisePlot.ipynb
- /CodeExamples/GuessGame.ipynb
- /CodeExamples/ImageShow.ipynb
---
 CodeExamples/FunctionCall.ipynb        | 37 +++++++++++---------------
 CodeExamples/FunctionFromCommand.ipynb | 23 ++++++----------
 CodeExamples/FunctionPlot.ipynb        | 26 +++++++-----------
 CodeExamples/FunctionScope.ipynb       |  4 +--
 CodeExamples/GaussianNoisePlot.ipynb   | 26 ++++++++----------
 CodeExamples/GuessGame.ipynb           | 32 ++++++++++------------
 CodeExamples/ImageShow.ipynb           | 11 +++-----
 7 files changed, 63 insertions(+), 96 deletions(-)

diff --git a/CodeExamples/FunctionCall.ipynb b/CodeExamples/FunctionCall.ipynb
index 7ccccce..5ff99bb 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 c3d36e9..c74510e 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 87dbb32..e7df587 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 64aef3d..fe02d56 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 230021a..dead37a 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 bbcec3a..5f67c56 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 bfbb1fc..6ce8f60 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"
    ]
   }
  ],
-- 
GitLab