diff --git a/CodeExamples/RangeLooptoList.ipynb b/CodeExamples/RangeLooptoList.ipynb index 6d7c54964dafe5437db08a097aecec52e8fe6d52..8f3ea345008c8775dddc5fbc789fe6e087bdb9b4 100644 --- a/CodeExamples/RangeLooptoList.ipynb +++ b/CodeExamples/RangeLooptoList.ipynb @@ -5,7 +5,7 @@ "id": "d6f58633", "metadata": {}, "source": [ - "# Reading and Printing Floats Main" + "# Range Loop to List" ] }, { @@ -16,17 +16,30 @@ "outputs": [], "source": [ "\"\"\"\n", - " Starter Python programm to read in and print a floating point number\n", + " Example to demonstrate a range loop to write theta and cos theta\n", + " to a list\n", "\"\"\"\n", "\n", + "import math\n", "\n", "def main():\n", - " \"\"\" Read in a number and print it\n", - " \"\"\"\n", - " x = float(input(\"Type in a floating point number : \"))\n", "\n", - " # Print it out\n", - " print(\"The number types was : \" + str(x))\n", + " n_point = 50\n", + " theta_data = [] # empty list \n", + " cos_data = [] # empty list\n", + "\n", + "\n", + " for i in range(0,n_point):\n", + " theta = 2.0*math.pi*i/n_point # Set theta\n", + " cos = math.cos(theta)\n", + " theta_data.append(theta) # Add values to list\n", + " cos_data.append(cos)\n", + "\n", + " # Do a default print (not very tidy output, replace this and \n", + " # a loop and make it nicer)\n", + " print(str(theta_data))\n", + " print(str(cos_data))\n", + "\n", "\n", "main()" ]