Varying very versatile variables

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
Introduction to C Programming
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual 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.
VARIABLES & CONSTANTS. Objective By the end of the lesson students should be able to:  Define a constant  Define a variable  Understand the rules for.
CPS120: Introduction to Computer Science
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Variables and Expressions CMSC 201 Chang (rev )
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
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 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.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
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.
Python Let’s get started!.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Thinking about programming
Math operations 9/19/16.
GCSE COMPUTER SCIENCE Practical Programming using Python
Agenda Introduction Computer Programs Python Variables Assignment
User Interaction and Variables
Chapter 2 Basic Computation
Input and Output Upsorn Praphamontripong CS 1110
Lesson 1 - Sequencing.
Python Let’s get started!.
Chapter 2 - Introduction to C Programming
Lesson 1 An Introduction
Introduction to Python Data Types and Variables
Variables, Expressions, and IO
Thinking about programming
Intro to C Tutorial 4: Arithmetic and Logical expressions
Chapter 2 - Introduction to C Programming
Chapter 2 Basic Computation
Thinking about programming
IDENTIFIERS CSC 111.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Learning Outcomes –Lesson 4
C++ Data Types Data Type
Chapter 2 - Introduction to C Programming
Data Types and Data Structures
Variables Kevin Harville.
Core Objects, Variables, Input, and Output
Variables In today’s lesson we will look at: what a variable is
Chapter 2 - Introduction to C Programming
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.
An Introduction to Programming
Introduction to C Programming
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Getting Started in Python
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Varying very versatile variables C’mon Mr. Hastings… that much alliteration is just unnecessary.

What is a variable? As in algebra and mathematics, a variable stands in for an unknown or a temporary value  Variables can change. In CS, a variable stores a value. A variable can ONLY hold one value at a time. A variable is given a name The names of a variables are in lowercase, have no spaces, cannot use keywords (like input or print) CS  computer science ( I will use this abbreviation often to save space) A variable can be named anything, from a single letter (like: x, y, a, b, or c), to words connected by an underscore (like: game_points, or time_allowed). When creating variable names, try to make the name mean something. We use the same variables often in a program, so having a letter like x may not help us remember what x stands for. A variable like “name” or “favorite_color” helps us know what its meaning is.

Storing information Think of a variable as a “memory location” The first time we set a variable, we are Initializing the variable If we reassign a value to a variable, we are destroying the previous value. (oh no!) Numerical values can be represented as either a float or an integer. Float  floating decimal point 72.9812 will not be in same location as 7.29 Integer  a whole number (no decimal) Initializing a variable is the same as ‘setting a variable equal to something’. In Python we type: variable_name = value The value is now recorded or stored in the variable_name. Variables can, and often do change. So, if we need a new value to replace what we initialized, we would simply enter again: variable_name = newvalue When this happens, the old value it destroyed / lost and the new value is now set. We can save numbers in our variables, but when we calculate or compare them to other numbers we have to differentiate them as either a integer (a whole number), or a float (like pi  3.14159). This is because the language need to know if you mean the value 10 or a string (just the one and zero key) A string is a ‘string’ of characters  the computer does not calculate or evaluate them.

Let’s rank Wicomico County Soccer Current top two teams: 1) Parkside 2) Mardela How would we create variables to represent the top two teams? Yes, this is just pretend. Using a variable name that makes sense will help us when we use the variables later on. What would you use as variable names? Why would you use those?

Swap rankings Imagine tonight – the teams swap rankings (#1 becomes #2 and vice versa) How would we swap variables without destroying values? What would need to happen? If we just replace one team variable with the other, the value is lost.