Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Creating a calculator.

Similar presentations


Presentation on theme: "Python Creating a calculator."— Presentation transcript:

1 Python Creating a calculator

2 Making a Calculator How do you use a calculator? Gray 80%

3 Making a Calculator Steps (Algorithm) Input the first number
Input the operator Input the second number Calculate the result (press the = key) Display the result Gray 80%

4 Making a Calculator Steps (Algorithm) Input the first number
Input the operator Input the Second number Calculate the result Display the result What happens to this data? Is it necessary to input this? What happens to this data? Where does this go? Gray 80% How many pieces of data are there? What datatype are they?

5 How a calculator works The calculator uses some important concepts which are similar to programming It has input (the numbers 9 and 4) – these are called variables Variables are held in temporary storage The calculator used an operator (/) divide. The calculator used an assignment operator ( =). In Python programming this does not mean equals Equals is written (==) a == 7, this means a has the same value as 7 a = 7, this means assign the value of 7 to a Gray 80%

6 Activity 1 – Part 1 The calculator program will add up two numbers and then return the answer to the screen Gray 80%

7 Activity 1 – Part 2 Extend your code so that it now multiplies, subtracts and divides the two numbers and displays the answer to each calculation on the screen at the same time. (use copy and paste to make this an easy task!)

8 Activity 1 Extension Allow the user to input the two numbers to be used in the calculations (Hint you will need to convert the number to an integer – see here for more details Allow the user to input which arithmetic operator they want to use 3. Allow the user to enter floating point numbers and display the result to 2 decimal places

9 Casting a Numeric Variable
Numbers typed into Python arrive as a string They must be converted to a number before using in arithmetic number1 “29” 29 number1 number1 “29”


Download ppt "Python Creating a calculator."

Similar presentations


Ads by Google