Variables and Expressions

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Introduction to C Programming
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
1 Lecture 6 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Introduction to Python
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Basic Input/Output and Variables Ethan Cerami New York
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Basic Elements of C++ Chapter 2.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Basic Elements of C++ Chapter 1.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
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,
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Introduction to Python Lesson 2a Print and Types.
Input, Output and Variables GCSE Computer Science – Python.
28 Formatted Output.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
© 2016, Mike Murach & Associates, Inc.
Topic: Python’s building blocks -> Statements
Data Types and Conversions, Input from the Keyboard
2.5 Another Java Application: Adding Integers
Introduction to Python and programming
Basic Elements of C++.
Functions CIS 40 – Introduction to Programming in Python
Java Programming: From Problem Analysis to Program Design, 4e
OUTPUT STATEMENTS GC 201.
Basic Elements of C++ Chapter 2.
Introduction to Python and programming
Introduction to Python and programming
Introduction to C++ Programming
Chapter 2: Basic Elements of Java
Variables and Expressions
Introduction to Python and programming
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
Topics Designing a Program Input, Processing, and Output
Python Lessons 9 & 10 Mr. Husch.
Core Objects, Variables, Input, and Output
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
EECE.2160 ECE Application Programming
COMPUTER PROGRAMMING SKILLS
EECE.2160 ECE Application Programming
Introduction to C Programming
Introduction to Python and programming
Presentation transcript:

Variables and Expressions Chapter 2

Statements and Expressions A statement is like a sentence in python. Made up of expressions. Expression are made up of 1 or more “building blocks” These building blocks are themselves expressions. print(“The answer is: “ + str(round(x * 5, 1)) )

“Building Blocks” of expressions Constants Operators Variables. Function definitions and calls. Classes and Object definitions and calls. Sequences

I.A: Numbers constants Integer constants: A “hard-coded” number without a decimal point. Internal representation Floating-point constants (float's) A number with a decimal point. Approximations to some numbers Handling this

I.B: String constants glyphs delimited by quotes 3 Types Escape Sequences

“Building Blocks” of expressions Constants Operators Variables. Function definitions and calls. Classes and Object definitions and calls. Sequences

II: Operators binary operators and operands. The first batch: + - * / // % ** Precedence and parentheses Type of result

“Building Blocks” of expressions Constants Operators Variables. Function definitions and calls. Classes and Object definitions and calls. Sequences

III: Variables What does the word "variable" mean to you? Algebra: y = 5x + 3 English: "He has variable moods." Others?? +x +y

III: Variables, cont. A variable is a name for a (group of) memory location(s). A "storage box" containing a value Python uses implicit declarations. Used in place of a constant = operator and augmented assignment operators

“Building Blocks” of expressions Constants Operators Variables. Function definitions and calls. Classes and Object definitions and calls. Sequences

IV: Functions A collection of (python) statements that accomplish some task. E.g. print: displays text on the screen. Two parts: definition (Ch. 6) call print("The answer is:", x * 5, sep="\t") parentheses, (needed even if there are no arguments) 0 or more arguments, separated by commas

IV: Functions to remember print input round min and max conversion functions int str float

“Building Blocks” of expressions Constants Operators Variables. Function definitions and calls. Classes and Object definitions and calls. Sequences

V: Objects, Classes Ch. 8 & 9 Everything in Python is an object. Objects have associated functions called methods. string methods

VI. Sequences Ch. 4 & 5 A group of "things" Preview: strings.