Python Creating a calculator.

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Advertisements

Binary Conversion In today’s lesson we will link together the binary and algorithm topics by looking at how to get the computer to: convert binary to decimal.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Section 3 Calculations National 4/5 Scratch Course.
Type Conversions Implicit Conversion Explicit Conversion.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Variables and Math in Code. Variables A variable is a storage block for information in your program “A” “A” Computer Program Memory Computer Program.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
OPERATIONS USING FRACTIONS. 1. Add, subtract, multiply and divide fractions with and without a calculator. 2. Convert between equivalent forms of fractions.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
Positive and Negative numbers. Negative numbers A positive or negative whole number, including zero, is called an integer. For example, –3 is an integer.
Program #2 Algorithm for Parking at PSU. Understanding the Assignment You will be writing a program to find out how much someone at PSU might be spending.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add
SCIENTIFIC NOTATION RULES. Rules for converting to Scientific Notation One non-zero number before the decimal One digit after the decimal If you are making.
Scientific Notation. What is Scientific Notation? Scientific notation is a way of writing extremely large or small measurements. The number is written.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
Converting to Percents. Decimals to Percents Decimals to Percents When converting decimals to percents, first you need to multiply the decimal with one.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Input, Output and Variables GCSE Computer Science – Python.
Mathematical Relationships Addition is the inverse or opposite of subtraction = – 5 = 5 Multiplication is repeated addition. 5 X 5 = 25 5.
Introduction to Programming
Numbers and arithmetic
Topics Designing a Program Input, Processing, and Output
Data Types and Conversions, Input from the Keyboard
How to survive WITHOUT your calculator!
Binary Positional Notation
Operations with Fractions and mixed numbers
Variables, Expressions, and IO
Introduction to Programming
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Lesson 1 Learning Objectives
Lesson 2: Program design process & Intro to code
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Week 3 Computer Programming Learning Objective:
Problem-Solving Steps Solve Problem-Solving Steps Solve
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Applying Exponent Rules: Scientific Notation
Python Lessons 9 & 10 Mr. Kalmes.
Fundamentals of Programming I Number Systems
Multiplying & Dividing Integers
Scientific Notation.
Learning Outcomes –Lesson 4
The Integer Song.
Introduction to Programming
Divide the number in C by 10.
We are starting JavaScript. Here are a set of examples
Reference semantics, variables and names
CST-115 Introduction to Computer Programming
Topics Designing a Program Input, Processing, and Output
B065: PROGRAMMING Variables 1.
Introduction to C Programming
Topics Designing a Program Input, Processing, and Output
Other types of variables
Introduction to Programming
Understanding Variables
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
Module 5 ● Vocabulary 1 a sensing block which will ask whatever question is typed into the block and display an input text box at the bottom.
Scientific Notation.
CS 1111 Introduction to Programming Spring 2019
More Basics of Python Common types of data we will work with
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
COMPUTING.
Mr. Peter Richard Complex Numbers Using the TI 83 Plus Calculator
Presentation transcript:

Python Creating a calculator

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

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%

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?

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%

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

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!)

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

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”