for while ' while ' for * for <var> in <sequence>: <body> $ %%" 0 *0

Size: px
Start display at page:

Download "for while ' while ' for * for <var> in <sequence>: <body> $ %%" 0 *0"

Transcription

1 # & for while while # * # & *, /01* for * 2 for <var> in <sequence>: <body>,var 0 2, /01* *** 0 *0 *& 4 00 *0* *

2 /01* 4 6, 4 * /01* Input the count of the numbers, n Initialize sum to 0 Loop n times Input a number, x Add x to sum Output average as sum/n 5 /01* # average1py # A program to average a set of numbers # Illustrates counted loop with accumulator def main: n = inputhow many numbers do you have? sum = 00 for i in rangen: x = inputenter a number >> sum = sum x print \nthe average of the numbers is, sum / n 8&99sum/n 6 /01* How many numbers do you have? 5 Enter a number >> 2 Enter a number >> 45 Enter a number >> 4 Enter a number >> 76 Enter a number >> 45 The average of the numbers is # 0** * 4** 0 * for * 4 * 0* 4 0** * 46 0

3 while <condition>: <body> condition,#0 if 2, 4 0* *, :,while 99 i = 0 while i <= 10: print i i = i 1 for for i in range11: print i while 2 i & 9 for while * ; i = 0 while i <= 10: print i 4*< 4 i 29*9, 9 8* i 9, 5

4 4 < *0 *0 6 * * 1**** 00* < count set moredata to yes while moredata is yes get the next data item process the item ask user if there is moredata * initialize sum to 00 initialize count to 0 set moredata to yes while moredata is yes input a number, x add x to sum add 1 to count ask user if there is moredata output sum/count # average2py # A program to average a set of numbers # Illustrates interactive loop with two accumulators def main: moredata = yes sum = 00 count = 0 while moredata[0] == y: x = inputenter a number >> sum = sum x count = count 1 moredata = raw_inputdo you have more numbers yes or no? print \nthe average of the numbers is, sum / count =, >?9@A* BCBCBC Enter a number >> 2 Do you have more numbers yes or no? y Enter a number >> 45 Do you have more numbers yes or no? yes Enter a number >> 4 Do you have more numbers yes or no? yup Enter a number >> 76 Do you have more numbers yes or no? y Enter a number >> 45 Do you have more numbers yes or no? nah The average of the numbers is 464

5 get the first data item while item is not the sentinel process the item get the next data item *,,* 4* *9 * # averagepy # A program to average a set of numbers # Illustrates sentinel loop using negative input as sentinel def main: sum = 00 count = 0 x = inputenter a number negative to quit >> while x >= 0: sum = sum x count = count 1 x = inputenter a number negative to quit >> print \nthe average of the numbers is, sum / count 5 Enter a number negative to quit >> 2 Enter a number negative to quit >> 45 Enter a number negative to quit >> 4 Enter a number negative to quit >> 76 Enter a number negative to quit >> 45 Enter a number negative to quit >> 1 The average of the numbers is 464 * * * 7 9

6 4 D* = 4 > A6 initialize sum to 00 initialize count to 0 input data item as a string, xstr while xstr is not empty convert xstr to a number, x add x to sum add 1 to count input next data item as a string, xstr Output sum / count # average4py # A program to average a set of numbers # Illustrates sentinel loop using empty string as sentinel def main: sum = 00 count = 0 xstr = raw_inputenter a number <Enter> to quit >> while xstr = : x = evalxstr sum = sum x count = count 1 xstr = raw_inputenter a number <Enter> to quit >> print \nthe average of the numbers is, sum / count Enter a number <Enter> to quit >> 4 Enter a number <Enter> to quit >> 2 Enter a number <Enter> to quit >> 0 Enter a number <Enter> to quit >> 25 Enter a number <Enter> to quit >> 44 Enter a number <Enter> to quit >> 227 Enter a number <Enter> to quit >> The average of the numbers is < # average5py # Computes the average of numbers listed in a file def main: filename = raw_inputwhat file are the numbers in? infile = openfilename,r sum = 00 count = 0 for line in infilereadlines: sum = sum evalline count = count 1 print \nthe average of the numbers is, sum / count

7 E 016 4readline, readline BC line = infilereadline while line = #process line line = infilereadline *G0 < H * * readline *BIC 6JBC 5 # average6py # Computes the average of numbers listed in a file def main: filename = raw_inputwhat file are the numbers in? infile = openfilename,r sum = 00 count = 0 line = infilereadline while line = : sum = sum evalline count = count 1 line = infilereadline print \nthe average of the numbers is, sum / count 8 **** if 4 * * >A ** sum = 00 count = 0 line = infilereadline while line = : #update sum and count for values in line line = infilereadline print \nthe average of the numbers is, sum/count 8,* sum count * * * sum 4count 5

8 8 for xstr in stringsplitline,,: sum = sum evalxstr count = count 1 8for line* 8 # average7py # Computes the average of numbers listed in a file # Works with multiple numbers on a line import string def main: filename = raw_inputwhat file are the numbers in? infile = openfilename,r sum = 00 count = 0 line = infilereadline while line = : for xstr in stringsplitline,,: sum = sum evalxstr count = count 1 line = infilereadline print \nthe average of the numbers is, sum / count 8 while for 4, 8 ** * * * if while,,true alse *G, * >while x >= 0A,, **, 2 2 5

9 if p1getx == p2getx: if p1gety == p2gety: # points are the same else: # points are different else: # points are different G*0**,6 G0 andornot and or *, <expr> and <expr> <expr> or <expr> 7 9 and *,, *, 4 / / /,,* P and Q or *,*, / / or *, or *,G** BC 7

10 not, not, 4 0,,, a or not b and c :*< * notandor 2 a or not b and c G& * *and if p1getx == p2getx and p2gety == p1gety: # points are the same else: # points are different * * 5 * 2 :*,< scorea == 15 or scoreb == 15 4,, 4* H0 6 while notscorea == 15 or scoreb == 15: #continue playing 7 9 9

11 2 *5 while notscorea == 15 or scoreb == 15 or \ scorea == 7 and scoreb == 0 or scoreb == 7 and scorea == 0: #continue playing 0 * * * * # 9 a >= 15 and a b >= 2 or b >= 15 and b a >= 2 a >= 15 or b >= 15 and absa b >= 2 *, 0, * M9J9 MJ L9J JJ JJ JJ and or 0 1 or* a or true == true and or a or b and c == a or b and a or c a and b or c == a and b or a and c notnot a == a E G* nota or b == not a and not b nota and b == not a or not b 4, while notscorea == 15 or scoreb == 15: #continue playing 0B4 C E G* while not scorea == 15 and not scoreb == 15: #continue playing

12 while scorea = 15 and scoreb = 15 # continue playing G<B4 C * * * not E G* *2, 5 if while, *** repeat get a number from the user until number is >= 0 4 *, * * while 5 5

13 4*, number = 1 while number < 0: number = inputenter a positive number: number ;*, break break, break,* * break while True: number = inputenter a positive number: if x >= 0: break # Exit loop if number is valid *, True *0 06 4, break,* if :6 4G * **< 5 5 while *0* number = 1 while number < 0: number = inputenter a positive number: if number < 0: print The number you entered was not positive 4G 0* 6 * break else while True: number = inputenter a positive number: if x >= 0: break # Exit loop if number is valid else: print The number you entered was not positive 55 5

14 : * while True: number = inputenter a positive number: if x >= 0: break # Loop exit print The number you entered was not positive :, ** : * while True: get next data item if the item is the sentinel: break process the item : : break * **,, * 0 * >0 A * while response[0] == y or response[0] == Y: 6H 0 while response[0] == y or Y: 4G*0< bool 9True alse 0== *bool

15 :** > A& alse True >>> bool0 alse >>> bool1 True >>> bool2 True >>> boolhello True >>> bool alse >>> bool[1,2,] True >>> bool[] alse 2 alse *2 0True 0, and, or not,,, *,, *, True *alse 5, and, *0*, **G,,,, *,* 7 79

16 * 0* and *, or*,*, response[0] == y or Y * :G2, response[0] == y or Y or,true?9@2bcbhc* 7 7 ** <Enter> ans ans = raw_inputwhat flavor fo you want [vanilla]: if ans: flavor = ans else: flavor = vanilla #<Enter>ans * * ans = raw_inputwhat flavor fo you want [vanilla]: flavor = ans or vanilla 1* True,* 6 flavor = raw_inputwhat flavor do you want [vanilla]: or vanilla &N0 0 * 6 7 7

Python Programming: An Introduction To Computer Science

Python Programming: An Introduction To Computer Science Python Programming: An Introduction To Computer Science Chapter 8 Booleans and Control Structures Python Programming, 2/e 1 Objectives æ To understand the concept of Boolean expressions and the bool data

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control ESCI 386 Scientific Programming, Analysis and Visualization with Python Lesson 5 Program Control 1 Interactive Input Input from the terminal is handled using the raw_input() function >>> a = raw_input('enter

More information

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID: CS177 MIDTERM 2 PRACTICE EXAM SOLUTION Name: Student ID: This practice exam is due the day of the midterm 2 exam. The solutions will be posted the day before the exam but we encourage you to look at the

More information

The While Loop. Objectives. Textbook. WHILE Loops

The While Loop. Objectives. Textbook. WHILE Loops Objectives The While Loop 1E3 Topic 6 To recognise when a WHILE loop is needed. To be able to predict what a given WHILE loop will do. To be able to write a correct WHILE loop. To be able to use a WHILE

More information

Programming in Python VI: Working with Files

Programming in Python VI: Working with Files Programming in Python VI: Working with Files Computer Science 105 Boston University David G. Sullivan, Ph.D. Escape Sequences Recall: we can surround strings by either single or double quotes. doing so

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information

PYTHON Basics http://hetland.org/writing/instant-hacking.html

PYTHON Basics http://hetland.org/writing/instant-hacking.html CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple

More information

Moving from C++ to VBA

Moving from C++ to VBA Introduction College of Engineering and Computer Science Mechanical Engineering Department Mechanical Engineering 309 Numerical Analysis of Engineering Systems Fall 2014 Number: 15237 Instructor: Larry

More information

Python Programming, 1/e 1

Python Programming, 1/e 1 "$% " " " ) " * -. ) / 0 ( + 34 average4.py A program to average a set of numbers Illustrates sentinel loop using empty string as sentinel def main(): sum = 0.0 count = 0 xstr = raw_input("enter a number

More information

Chapter 2 Writing Simple Programs

Chapter 2 Writing Simple Programs Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle Software Development Process Figure out the problem - for simple problems

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Social Science Research Lab American University, Washington, D.C. Web. www.american.edu/provost/ctrl/pclabs.cfm Tel. x3862 Email. SSRL@American.edu Course Objective This course provides

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

Introduction to Python for Text Analysis

Introduction to Python for Text Analysis Introduction to Python for Text Analysis Jennifer Pan Institute for Quantitative Social Science Harvard University (Political Science Methods Workshop, February 21 2014) *Much credit to Andy Hall and Learning

More information

Computational Mathematics with Python

Computational Mathematics with Python Boolean Arrays Classes Computational Mathematics with Python Basics Olivier Verdier and Claus Führer 2009-03-24 Olivier Verdier and Claus Führer Computational Mathematics with Python 2009-03-24 1 / 40

More information

How do sort this list using one line? a_list.sort()

How do sort this list using one line? a_list.sort() Review Questions for lists and File (read and write): Make sure to review Midterm 1 and midterm 2, all samples for midterms as well. Review all of the homework, class examples and readings exercises. Make

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

Introduction to: Computers & Programming: Input and Output (IO)

Introduction to: Computers & Programming: Input and Output (IO) Introduction to: Computers & Programming: Input and Output (IO) Adam Meyers New York University Summary What is Input and Ouput? What kinds of Input and Output have we covered so far? print (to the console)

More information

CRASH COURSE PYTHON. Het begint met een idee

CRASH COURSE PYTHON. Het begint met een idee CRASH COURSE PYTHON nr. Het begint met een idee This talk Not a programming course For data analysts, who want to learn Python For optimizers, who are fed up with Matlab 2 Python Scripting language expensive

More information

Computational Mathematics with Python

Computational Mathematics with Python Computational Mathematics with Python Basics Claus Führer, Jan Erik Solem, Olivier Verdier Spring 2010 Claus Führer, Jan Erik Solem, Olivier Verdier Computational Mathematics with Python Spring 2010 1

More information

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

System.out.println(\nEnter Product Number 1-5 (0 to stop and view summary) : Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class

More information

Enter Here -->>> Business Credit Building Course Scam or Work?

Enter Here -->>> Business Credit Building Course Scam or Work? Enter Here -->>> Business Credit Building Course Scam or Work? > Visit Now < TAG LIST: Best way to get business credit building course, build business credit uk for sale six figure business credit, best

More information

Python Basics. S.R. Doty. August 27, 2008. 1 Preliminaries 4 1.1 What is Python?... 4 1.2 Installation and documentation... 4

Python Basics. S.R. Doty. August 27, 2008. 1 Preliminaries 4 1.1 What is Python?... 4 1.2 Installation and documentation... 4 Python Basics S.R. Doty August 27, 2008 Contents 1 Preliminaries 4 1.1 What is Python?..................................... 4 1.2 Installation and documentation............................. 4 2 Getting

More information

SUMMARY. Satellite is an application Two Sigma wrote to monitor, alert, and auto-administer our Mesos clusters.

SUMMARY. Satellite is an application Two Sigma wrote to monitor, alert, and auto-administer our Mesos clusters. SUMMARY Example of what Satellite can do: When swap falls below 1 day, turn the host off; if 20% of the cluster is turned off, send a pagerduty alert. Satellite is an application Two Sigma wrote to monitor,

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Positional Numbering System

Positional Numbering System APPENDIX B Positional Numbering System A positional numbering system uses a set of symbols. The value that each symbol represents, however, depends on its face value and its place value, the value associated

More information

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal: Exercises 1 - number representations Questions 1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal: (a) 3012 (b) - 435 2. For each of

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

SNMP-1 Configuration Guide

SNMP-1 Configuration Guide SNMP-1 Configuration Guide You must configure the Net Logic Card before it can operate properly. You have two methods to configure the Net Logic Card: Using telnet or terminal. Using Telnet 1. Make sure

More information

Repetition Using the End of File Condition

Repetition Using the End of File Condition Repetition Using the End of File Condition Quick Start Compile step once always g++ -o Scan4 Scan4.cpp mkdir labs cd labs Execute step mkdir 4 Scan4 cd 4 cp /samples/csc/155/labs/4/*. Submit step emacs

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

Conditionals (with solutions)

Conditionals (with solutions) Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

More information

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003 Basic C Shell helpdesk@stat.rice.edu 11th August 2003 This is a very brief guide to how to use cshell to speed up your use of Unix commands. Googling C Shell Tutorial can lead you to more detailed information.

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:

More information

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification: Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Adding and Subtracting Positive and Negative Numbers

Adding and Subtracting Positive and Negative Numbers Adding and Subtracting Positive and Negative Numbers Absolute Value For any real number, the distance from zero on the number line is the absolute value of the number. The absolute value of any real number

More information

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project CE 311 K Introduc/on to Computer Methods VB Controls and Events Daene C. McKinney Introduc)on Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project 1 Why Visual

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Chapter 7 Decision Structures Python Programming, 1/e 1 Objectives To understand the programming pattern simple decision and its implementation using

More information

Reading Input From A File

Reading Input From A File Reading Input From A File In addition to reading in values from the keyboard, the Scanner class also allows us to read in numeric values from a file. 1. Create and save a text file (.txt or.dat extension)

More information

Character Translation Methods

Character Translation Methods Supplement to: Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition. This file may be duplicated or printed for classroom use, as long as the author name, book title, and copyright notice

More information

a high-level language that translate a set of instructions into! )!<24<=.'8'.!.)$4#)4'!,<),!,&)$*.),'!)!*',!->!2$*,&#?,2-$*!2$,-!5)?<2$'!

a high-level language that translate a set of instructions into! )!<24<=.'8'.!.)$4#)4'!,<),!,&)$*.),'!)!*',!->!2$*,&#?,2-$*!2$,-!5)?<2$'! Python!"#$%&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"#$%!"&''%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!()*+!,-!.')&$/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&')0!)$0!1&2,'%

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

?<BACBC;@@A=2(?@?;@=2:;:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

?<BACBC;@@A=2(?@?;@=2:;:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NGS data format NGS data format @SRR031028.1708655 GGATGATGGATGGATAGATAGATGAAGAGATGGATGGATGGGTGGGTGGTATGCAGCATACCTGAAGTGC BBBCB=ABBB@BA=?BABBBBA??B@BAAA>ABB;@5=@@@?8@:==99:465727:;41'.9>;933!4 @SRR031028.843803

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

LINEAR INEQUALITIES. less than, < 2x + 5 x 3 less than or equal to, greater than, > 3x 2 x 6 greater than or equal to,

LINEAR INEQUALITIES. less than, < 2x + 5 x 3 less than or equal to, greater than, > 3x 2 x 6 greater than or equal to, LINEAR INEQUALITIES When we use the equal sign in an equation we are stating that both sides of the equation are equal to each other. In an inequality, we are stating that both sides of the equation are

More information

A Java array is kind of like a credit card holder Sleeves to put credit cards in

A Java array is kind of like a credit card holder Sleeves to put credit cards in Intro Arrays Page 1 Intro Arrays Thursday, February 16, 2012 11:59 AM A Java array is kind of like a credit card holder Sleeves to put credit cards in Outer case of holder Intro Arrays Page 2 Numbered

More information

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables AMATH 352 Lecture 3 MATLAB Tutorial MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical analysis. It provides an environment for computation and the visualization. Learning

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

More information

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 6 - File IO

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 6 - File IO ESCI 386 Scientific Programming, Analysis and Visualization with Python Lesson 6 - File IO 1 Opening/Closing Files A file is opened for reading using the open statement f = open(file_name, r ) This returns

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from

More information

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel. Topics 1 Visual Basic Application Macro Language What You Can Do with VBA macro Types of VBA macro Recording VBA macros Example: MyName () If-Then statement Example: CheckCell () For-Next Loops Example:

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

Scientific Notation. Section 7-1 Part 2

Scientific Notation. Section 7-1 Part 2 Scientific Notation Section 7-1 Part 2 Goals Goal To write numbers in scientific notation and standard form. To compare and order numbers using scientific notation. Vocabulary Scientific Notation Powers

More information

JavaScript: Arrays. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Arrays. 2008 Pearson Education, Inc. All rights reserved. 1 10 JavaScript: Arrays 2 With sobs and tears he sorted out Those of the largest size... Lewis Carroll Attempt the end, and never stand to doubt; Nothing s so hard, but search will find it out. Robert

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

7-1 Java Au Naturel by William C. Jones 7-1

7-1 Java Au Naturel by William C. Jones 7-1 7-1 Java Au Naturel by William C. Jones 7-1 7 Arrays Overview In this chapter you will learn about arrays in the context of a personnel database system for a commercial company. An array lets you store

More information

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution 16. Recursion COMP 110 Prasun Dewan 1 Loops are one mechanism for making a program execute a statement a variable number of times. Recursion offers an alternative mechanism, considered by many to be more

More information

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65 Simulation Tools Python for MATLAB Users I Claus Führer Automn 2009 Claus Führer Simulation Tools Automn 2009 1 / 65 1 Preface 2 Python vs Other Languages 3 Examples and Demo 4 Python Basics Basic Operations

More information

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook. Elementary Number Theory and Methods of Proof CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 1 Number theory Properties: 2 Properties of integers (whole

More information

The Little Man Computer

The Little Man Computer The Little Man Computer The Little Man Computer - an instructional model of von Neuman computer architecture John von Neuman (1903-1957) and Alan Turing (1912-1954) each independently laid foundation for

More information

Click Here -->>> Business Credit Building Course User Experience > Check Here <

Click Here -->>> Business Credit Building Course User Experience > Check Here < How to build business credit 2013, how to build credit for new small business, how to build business credit with experian. Click Here -->>> Business Credit Building Course User Experience > Check Here

More information

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail ALGORITHMS AND FLOWCHARTS By Miss Reham Tufail ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe

More information

2 Matlab Programming, IO, and strings

2 Matlab Programming, IO, and strings 2 Matlab Programming, IO, and strings Programming is the basic skill for implementing numerical methods. In this chapter we describe the fundamental programming constructs used in MATLAB and present examples

More information

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors. The Prime Numbers Before starting our study of primes, we record the following important lemma. Recall that integers a, b are said to be relatively prime if gcd(a, b) = 1. Lemma (Euclid s Lemma). If gcd(a,

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Computational Mathematics with Python

Computational Mathematics with Python Numerical Analysis, Lund University, 2011 1 Computational Mathematics with Python Chapter 1: Basics Numerical Analysis, Lund University Claus Führer, Jan Erik Solem, Olivier Verdier, Tony Stillfjord Spring

More information

Intersection of Convex Objects: The Method of Separating Axes

Intersection of Convex Objects: The Method of Separating Axes Intersection of Convex Objects: The Method of Separating Axes David Eberly Geometric Tools, LLC http://www.geometrictools.com/ Copyright c 1998-2016. All Rights Reserved. Created: January 28, 2001 Last

More information

Computer Programming Lecturer: Dr. Laith Abdullah Mohammed

Computer Programming Lecturer: Dr. Laith Abdullah Mohammed Algorithm: A step-by-step procedure for solving a problem in a finite amount of time. Algorithms can be represented using Flow Charts. CHARACTERISTICS OF AN ALGORITHM: Computer Programming Lecturer: Dr.

More information

Reminder: Complexity (1) Parallel Complexity Theory. Reminder: Complexity (2) Complexity-new

Reminder: Complexity (1) Parallel Complexity Theory. Reminder: Complexity (2) Complexity-new Reminder: Complexity (1) Parallel Complexity Theory Lecture 6 Number of steps or memory units required to compute some result In terms of input size Using a single processor O(1) says that regardless of

More information

Reminder: Complexity (1) Parallel Complexity Theory. Reminder: Complexity (2) Complexity-new GAP (2) Graph Accessibility Problem (GAP) (1)

Reminder: Complexity (1) Parallel Complexity Theory. Reminder: Complexity (2) Complexity-new GAP (2) Graph Accessibility Problem (GAP) (1) Reminder: Complexity (1) Parallel Complexity Theory Lecture 6 Number of steps or memory units required to compute some result In terms of input size Using a single processor O(1) says that regardless of

More information

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int. Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).

More information

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS. Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 Name: SOLUTIONS Athena* User Name: Instructions This quiz is 50 minutes long. It contains

More information

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to Chapter 3 Writing Simple Programs Charles Severance Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.

More information

SAS Macros as File Management Utility Programs

SAS Macros as File Management Utility Programs Paper 219-26 SAS Macros as File Management Utility Programs Christopher J. Rook, EDP Contract Services, Bala Cynwyd, PA Shi-Tao Yeh, EDP Contract Services, Bala Cynwyd, PA ABSTRACT This paper provides

More information

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10 Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution

More information

Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Section IV.1: Recursive Algorithms and Recursion Trees

Section IV.1: Recursive Algorithms and Recursion Trees Section IV.1: Recursive Algorithms and Recursion Trees Definition IV.1.1: A recursive algorithm is an algorithm that solves a problem by (1) reducing it to an instance of the same problem with smaller

More information

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

More information

Math 0306 Final Exam Review

Math 0306 Final Exam Review Math 006 Final Exam Review Problem Section Answers Whole Numbers 1. According to the 1990 census, the population of Nebraska is 1,8,8, the population of Nevada is 1,01,8, the population of New Hampshire

More information

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1 United States Naval Academy Electrical and Computer Engineering Department EC262 Exam 29 September 2. Do a page check now. You should have pages (cover & questions). 2. Read all problems in their entirety.

More information

Algorithm Design and Recursion

Algorithm Design and Recursion Chapter 13 Algorithm Design and Recursion Objectives To understand basic techniques for analyzing the efficiency of algorithms. To know what searching is and understand the algorithms for linear and binary

More information

Identifying Invalid Social Security Numbers

Identifying Invalid Social Security Numbers ABSTRACT Identifying Invalid Social Security Numbers Paulette Staum, Paul Waldron Consulting, West Nyack, NY Sally Dai, MDRC, New York, NY Do you need to check whether Social Security numbers (SSNs) are

More information

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++ MS Visual C++ Introduction 1 Quick Introduction The following pages provide a quick tutorial on using Microsoft Visual C++ 6.0 to produce a small project. There should be no major differences if you are

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Package HadoopStreaming

Package HadoopStreaming Package HadoopStreaming February 19, 2015 Type Package Title Utilities for using R scripts in Hadoop streaming Version 0.2 Date 2009-09-28 Author David S. Rosenberg Maintainer

More information

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.

More information

Reading and Writing PCD Files The PCD File Format The Grabber Interface Writing a Custom Grabber PCL :: I/O. Suat Gedikli, Nico Blodow

Reading and Writing PCD Files The PCD File Format The Grabber Interface Writing a Custom Grabber PCL :: I/O. Suat Gedikli, Nico Blodow PCL :: I/O Suat Gedikli, Nico Blodow July 1, 2011 Outline 1. Reading and Writing PCD Files 2. The PCD File Format 3. The Grabber Interface 4. Writing a Custom Grabber global functions in the namespace

More information

CS 121 Intro to Programming:Java - Lecture 11 Announcements

CS 121 Intro to Programming:Java - Lecture 11 Announcements CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take

More information

Python Evaluation Rules

Python Evaluation Rules Python Evaluation Rules UW CSE 160 http://tinyurl.com/dataprogramming Michael Ernst and Isaac Reynolds mernst@cs.washington.edu August 2, 2016 Contents 1 Introduction 2 1.1 The Structure of a Python Program................................

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information