Data Types and Maths Programming Guides.

Slides:



Advertisements
Similar presentations
Objective: Dealing with data in C++ Agenda: Notes Essay Help.
Advertisements

Variables – the Key to Programming. ICS-3M1 - Mr. Martens - Variables Part 1 What is a Variable? A storage location that is given a “name” You can store.
Python November 14, Unit 7. Python Hello world, in class.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
From Scratch to Python Learn to program like the big boys / girls!
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Logical or Boolean Data stored in Boolean form can only be one of two available values. Think of a light switch – it’s on or off. Examples include: YES.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Variables Damian Gordon. Variables We know what a variable is from maths. We’ve all seen this sort of thing in algebra: 2x – 10 = 0 2x = 10 X = 5.
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.
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
C OMPUTER P ROGRAMMING 1 Assignment. A SSIGNMENT We have used gets to input a value into variable The second way to give a variable a value is known as.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
A: A: double “4” A: “34” 4.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
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,
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
GCSE Computing: Programming GCSE Programming Remembering Python.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Input, Output and Variables GCSE Computer Science – Python.
Data Types Mr Tottman Link. Data Types Programs need to use data for calculations and for output to various devices The best programs will always use.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
CST 1101 Problem Solving Using Computers
Chapter 2 Basic Computation
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Data Types and Conversions, Input from the Keyboard
Variables, Expressions, and IO
Computational Thinking
Computational Thinking
Variables ,Data Types and Constants
Chapter 2.
Review Operation Bingo
Computers & Programming Languages
Python Lessons 9 & 10 Mr. Kalmes.
Learning Outcomes –Lesson 4
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Coding Concepts (Data- Types)
Python Lessons 9 & 10 Mr. Husch.
Variables Kevin Harville.
Variables Here we go.
Variables and Computer Memory
C# Revision Cards Data types
Java: Variables, Input and Arrays
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.
Millennium High School Agenda Calendar
More Basics of Python Common types of data we will work with
Variables and Constants
Introduction to Python
Python Creating a calculator.
Section 6 Primitive Data Types
Presentation transcript:

Data Types and Maths Programming Guides

Data Types and Maths Integer String Real / Float Character Boolean There are several different types of data that your programs will need to work with. Here are some of them: Integer This means any whole number. If the computer knows the data is an integer it can do maths with the data String This means any combination of keyboard characters (letters, numbers symbols) Real / Float This means any decimal (fractional) number Character This means any single character that you might find on a keyboard. Boolean This data type has just two values: True & False.

Data Types and Maths Computers store values in variables In order for the computer to understand our inputs, it needs to know what type of data our input is. If a variable is to hold a word, we must tell the computer that the variable is to contain a string. If a variable is to hold a whole number, we must tell the computer that the variable is to contain an integer – so it can do calculations. If we don’t do this the program will not be able to perform the correct operations on the data.

num1 = input(“please enter a number”) Data Types and Maths If we want our program to work with numbers we must tell the program that certain variables will hold numbers. When we input a number into our program num1 = input(“please enter a number”) python automatically sets the variable as a string (think of it as if python reads the input as twenty instead of 20). If we want to do maths with the ‘inputs’ we need to tell the computer that the variable contains a number (integer).

Data Types and Maths To do this we need to convert the variable to an ‘integer’ or ‘real’ data type. Above you can see that two numbers have been entered and stored in variables num1 and num2. As python stores inputs as strings we need to convert these variables into integers.

What’s going on? Twenty Nine Twenty Nine 29 29 Mr Int. Num1 Variable User types in 29 but python reads it as a string (so think of it like python reading 29 as twenty nine). Twenty Nine Num1 I’m telling the computer that this variable contains a number not a string! 29 29 Twenty Nine Variable Variable Mr Int.

Data Types and Maths 14 Visualisation of the Process: Num1 Num2 Num1 Five Num2 Nine 5 9 Num1 Five Num2 Nine 14 Answer 5 + 9 14 14 Answer

Data Types and Maths What if we want python to read our inputs as decimal numbers instead of integers? Instead of using the int() function to convert a string to an integer, we can use the float() function to convert a string to a decimal number, so that python can perform maths on the number correctly.