New functions – subtraction, multiplication, and division
Now that we have created an addition()
function that accepts data from the user and converts it into numbers, we are ready to create functions for subtraction, multiplication, and division.
If you are coming back to this after a break, perform the following steps:
Open your Python shell so that you can test your code as you write.
Next, open your text editor (jEdit in Mac/Linux and Notepad ++ in Windows).
Have both windows open on your desktop as you program.
When you successfully write and test a line or a few lines of code in the Python shell, copy the lines into your text editor and then Save Your Work to the
first_calc.py
file that you created earlier in this chapter.
Tip
Save your work early and as often as you can! Avoid being upset by accidentally erasing your code!
Subtraction
For the next part of our calculator, we will make our subtraction function. We will follow the same prompts as we used for the addition function to create a...