ECS15 for and sequence. Comments  Another way to repeat.

Slides:



Advertisements
Similar presentations
What type of data can a variable hold?
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Guide to Programming with Python
Group practice in problem design and problem solving
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
CIS Computer Programming Logic
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
© 2004 Pearson Addison-Wesley. All rights reserved February 17, 2006 The ‘while’ Statement ComS 207: Programming I (in Java) Iowa State University, SPRING.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Xin Liu Feb 4, * Use midterm questions for previous 231/217 midterms for practices * ams
Python Conditionals chapter 5
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.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 The switch Statement The switch statement provides another way.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/29 The switch Statement The switch statement provides another way.
Syntax (2).
Loops & List Intro2CS – week 3 1. Loops -- Motivation Sometimes we want to repeat a certain set of instructions more than once. The number of repetitions.
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there.
Last Week Modules Save functions to a file, e.g., filename.py The file filename.py is a module We can use the functions in filename.py by importing it.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Student Q and As from 5.1 – 5.7, 5.11 Students of CS104, Fall 2013 (and me)
COMP Loop Statements Yi Hong May 21, 2015.
12 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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.
Escape sequence Certain characters, preceded by a backslash ( \ ), are known as escape sequences They are used to display certain characters, or as display.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Python Strings. String  A String is a sequence of characters  Access characters one at a time with a bracket operator and an offset index >>> fruit.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Fundamentals 2.
7 - Programming 7J, K, L, M, N, O – Handling Data.
String and Lists Dr. José M. Reyes Álamo.
Scientific Programming in Python -- Cheat Sheet
Whatcha doin'? Aims: To start using Python. To understand loops.
Types CSCE 314 Spring 2016.
ECE Application Programming
Chapter 4 – Fundamental Data Types
Basic operators - strings
Arrays, For loop While loop Do while loop
Computers & Programming Languages
Nate Brunelle Today: Repetition, Repetition
Chapter 2: Java Fundamentals
String and Lists Dr. José M. Reyes Álamo.
Variables Kevin Harville.
Introduction to Computer Science
Unit 3: Variables in Java
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.
Boolean in C++ CSCE 121.
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

ECS15 for and sequence

Comments  Another way to repeat.

While loop example count = 1 while count < 11: print count count = count+1

for loop for count in range(1,11): print count  Shorter and sweeter, but exactly the same effect  range(start,stop) is a built-in function  Produces the sequence [1,2,…,9,10]

Counting forward for count in range(0,50,5): print i

Counting backward for count in range(10,1,-1): print i

Using a string word= “my string” for char in word: print char,

Sequences  A sequence is an ordered collection of objects.  Printed enclosed in brackets (the brackets are not part of the sequence)  Examples: [5,7,1,3] – no reason they have to be in numerical order [“r”, ”p”, ”s”] – a sequence of one-letter strings

“r” in [“r”, “p”, “s”]  Check if something is in the sequence: “r” in [“r”, “p”, “s”] is a Boolean expression, and its value is True.  “x” in [“r”, “p”, “s”] is a Boolean expression, and its value is False.

Strings are sequences  A string is a sequence of letters  Well, really, a string is a sequence of characters  Letters, digits, punctuation marks, spaces, are all characters.  ‘ecs15-f08’ is a sequence of characters.  [‘c’, ’o’, ’w’] is a sequence of strings, each one character long.

Checking numerical input x = raw_input(“Enter interest rate: “) # x is a string  Sometimes we want to convert x to a number using int(x) or float(x)  If x is not a string which is a valid integer or floating point number, this causes an error!

Check each digit  Look at them one by one  Is each one a digit? if y in ‘ ’:

goodInput = False # So far, no valid input while not goodInput: x = raw_input("Enter an integer: ") goodInput = True for char in x : if char not in ' ': goodInput = False if not goodInput: print "That was not an integer!" Nested blocks