In this example you will learn to create a simple calculator that can add, subtract, multiply or divide depending upon the input from the user.
To understand this example, you should have the knowledge of the following Python programming topics: Python Functions Python Function Arguments Python User-defined Functions
In this program, we ask the user to choose an operation. Options 1, 2, 3, and 4 are valid. If any other input is given, Invalid Input is displayed and the loop continues until a valid option is selected. Two numbers are taken and an if...elif...else branching is used to execute a particular section. User-defined functions add(), subtract(), multiply() and divide() evaluate respective operations and display the output.