Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Data Types and Expressions
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Introduction to Python
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
JavaScript, Third Edition
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Intro to CS – Honors I Programming Basics GEORGIOS PORTOKALIDIS
CIS Computer Programming Logic
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
2440: 211 Interactive Web Programming Expressions & Operators.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
CPS120: Introduction to Computer Science
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Characters and tokens Characters are the basic building blocks in C program, equivalent to ‘letters’ in English language Includes every printable character.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Primitive Variables.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Working With Objects Tonga Institute of Higher Education.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
CPS120: Introduction to Computer Science Variables and Constants.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Java Variables and Types
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Variables and Primative Types
Topics The if Statement The if-else Statement Comparing Strings
Section 3.2c Strings and Method Signatures
Java Programming: From Problem Analysis to Program Design, 4e
Building Java Programs Chapter 2
Topics The if Statement The if-else Statement Comparing Strings
Data Types, Identifiers, and Expressions
Types, Truth, and Expressions (Part 2)
Variables ICS2O.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Types, Truth, and Expressions (Part 2)
Introduction to Primitive Data types
Chapter 2: Java Fundamentals
Python Primer 1: Types and Operators
Core Objects, Variables, Input, and Output
Chapter 2: Java Fundamentals
Chapter 2 Programming Basics.
Chapter 2 Primitive Data Types and Operations
Introduction to Primitive Data types
Types, Truth, and Expressions (Part 2)
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Chapter 3 Primitive Expressions

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Overview

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Variables A variable connects a name to one value

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Variables One value could also wear multiple labels - meaning that a single value is connected to multiple variables.

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Variables But one important rule at this party is that labels must be unique - two values can’t have the same label (i.e., variable name) at once.

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Variable Assignment Variables are connected to values through through assignment - this is how we make a value wear a label. Consider this example where a new value associated with the variable force (39.6) is derived from a standard physics relationship:

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Variable Assignment Here we illustrate dynamic typing by letting the variable foo take on four different values and four different corresponding types:

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Variable Assignment

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Rules for Naming Variables the first character must be a letter of any case or language or an under- score, continuation characters may include most characters but not whitespace or punctuation that has special meaning in Python (e.g., period, comma, parenthesis, brackets), and identifiers can’t have the same name as words reserved by the Python language as a keyword (e.g., and, if, def, and else ).

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Rules for Naming Variables

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Rules for Naming Variables variable names are lower case and words are separated with underscores (e.g., standard_deviation), class names are capitalized camel case (e.g., ColorMatrix), identifiers that begin with one or more underscores have special meaning that we will discuss later, identifiers shouldn’t have the same name as built-in identifiers (e.g., int, float, list, tuple,dir).

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Choosing ‘Good’ Variable Names Is the name consistent with existing naming conventions? Does this value have important units (grams, meters, moles, etc.) that are not obvious from its type or usage? Does the name unnecessarily use negative logic or other counter intuitive conventions? You should consider using is_enabled instead of is_not_enabled.

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Choosing ‘Good’ Variable Names Is the name descriptive? If you had seen this variable for the first time would the name make sense? Is the name too wordy, long, or redundant? Is the name too short or does it use uncommon abbreviations?

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Principle 5 (Code Should Read Like Poetry) Code written with good variable names allows the code to be read almost like poetry. Use variable names to tell a coherent story about what a computation accomplishes. Poor variable names hide the meaning of the code.

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Principle 5 (Code Should Read Like Poetry) Consider this perfectly correct piece of code: Choose names that reveal the codes purpose:

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Booleans

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Logical Expressions

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Logical Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Logical Operator Truth Table

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. if statement

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Block

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Numbers

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Numbers

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Numbers

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Arithmetic Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Arithmetic Expression

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Clock Arithmetic

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Clock Arithmetic

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Comparison Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Comparison Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Comparison Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Literal

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Literal String Syntax

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Escape Sequences

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Escape Sequences

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Operators (Slicing)

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Operators

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Methods

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. String Methods

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Conversion Functions

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Lists and Dictionaries

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Lists and Dictionaries