Python Programming :
Mathematical Operators
2
ENGAGE
Can you find the 3 mistakes in this code?
2
Engage
3
Mathematical Operators
Learning Objective:
I can utilise mathematical operators in my programs.
Learning outcome:
Write a program in python that can meet the required needs.
4
iCan()
iCan.Explore()
I have used addition within my program to add two user input numbers together.
iCan.Enhance()
I have improved my code to include all mathematical operators to apply to the user's input numbers.
iCan.Excel()
I have improved my code to give the user the option on which mathematical operator to apply to their input numbers.
5
Mathematical operators
Computers are able to perform simple and complex mathematical functions considerably faster than humans.
Using Python, you can code a sum which would be very difficult to solve using a simple calculator
6
How to open Python – A reminder
7
1
2
3
What's the difference
What the difference between the following statements?
Types them in one at a time
Press the ‘F5’ key on your keyboard and see what happens!
8
Strings and Integers
Quote marks are used by Python to specify ‘strings of text’ meaning Python will print the exact phrase
Numbers on their own are treated as ‘integers’ or whole numbers
9
Variables
This isn’t a useful calculator because we have to ‘Hard code’ the numbers.
We can use variables to avoid this
Copy the example and press F5
10
input()
11
We can use the input() code from last lesson to allow the user to choose their own example
Press F5 and see what happens
Casting
12
Onenote
Using the example below to help you. Complete the explore section on your onenote.
13
Excel (support)
14
Make your code better by allowing the user to choose which mathematical operator the program should use.
Hints