1 of 14

Python Programming :

Mathematical Operators

2

2 of 14

ENGAGE

Can you find the 3 mistakes in this code?

2

3 of 14

Engage

  1. Print needs to written in lowercase.

  • Messages to be printed need to be surrounding in quotes.

  • The variable “a” needs to be outside the quotes.

3

4 of 14

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

5 of 14

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

6 of 14

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

7 of 14

How to open Python – A reminder

7

1

2

3

8 of 14

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

9 of 14

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

10 of 14

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

11 of 14

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

12 of 14

Casting

  • By default, Python treats all input() as text strings.
  • We need to tell Python to treat these inputs as integers, to do this we use ‘casting’ to switch the variable from a string to an integer

12

13 of 14

Onenote

Using the example below to help you. Complete the explore section on your onenote.

13

14 of 14

Excel (support)

14

Make your code better by allowing the user to choose which mathematical operator the program should use.

Hints

    • You will need to ask the user what type of operator they need.
    • You will need to check what they have chosen using if/elif/else.