{ "cells": [ { "cell_type": "markdown", "id": "6838b2de", "metadata": {}, "source": [ "# Hello" ] }, { "cell_type": "code", "execution_count": null, "id": "4200d243", "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", " Example program to show that you read in a function name from the\n", " command line and then ececute it\n", "\n", " Try with fnOne, fnTwo, it it also works for math.cos, math.sin, math.log etc\n", "\"\"\"\n", "\n", "import math\n", "\n", "\n", "def fnOne(y):\n", " \"\"\"\n", " Create a function\n", " \"\"\"\n", " print(\"Funcion one called with y = \" + str(y))\n", " return y # Just return the given vaue\n", "\n", "\n", "def fnTwo(y):\n", " \"\"\"\n", " Create a second function\n", " \"\"\"\n", " print(\"Funcion two called with y = \" + str(y))\n", " return 2*y # Just return double the value\n", "\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()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }