SI Networked Computing: Storage, Communication, and Processing, Winter 2009

Similar documents
Chapter 2 Writing Simple Programs

Introduction to Computer Programming for Non-Majors

CITS 4406 Problem Solving & Programming

Python Programming: An Introduction to Computer Science

Introduction to Computer Programming for Non-Majors

Python Programming: An Introduction to Computer Science

Lecture Writing Programs. Richard E Sarkis CSC 161: The Art of Programming

Jython. secondary. memory

Getting Started with Python

Constants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter

Variables, Expressions, and Statements

Fundamentals of Programming (Python) Getting Started with Programming

Programming with Python

Python Programming: An Introduction to Computer Science

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

Variable and Data Type I

Basic Syntax - First Program 1

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

" # # if $ " %&% # ifelse $ " #&% # ifelif-else $ +bool ##%# # #.* $ ## # .# *#%$ % ## % .#*#%*

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

CMSC 201 Computer Science I for Majors

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output

About Variables in Python F E B 1 1 T H

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

File processing and decision structures

Introduction to Computer Programming for Non-Majors

Variable and Data Type I

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Variables, expressions and statements

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Introduction to Computer Programming for Non-Majors

CSCE 110 Programming I

Python Programming: An Introduction to Computer Science

ENGR 101 Engineering Design Workshop

CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us?

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Worlframalpha.com Facebook Report

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

Flow Control: Branches and loops

Introduction to Problem Solving and Programming in Python.

Python. Objects. Geog 271 Geographic Data Analysis Fall 2010

Algorithms and Data Structures

PROGRAMMING FUNDAMENTALS

The Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1

Unit E Step-by-Step: Programming with Python

The float type and more on variables FEB 6 TH 2012

Python for Informatics

Beyond Blocks: Python Session #1

Getting started with programming For geospatial data analysis. Robert Hijmans UC Davis

Exceptions. Exceptions. Can have multiple except suites and/or one unnamed except suite

Beyond programming. CS 199 Computer Science for Beginners Spring 2009 Lois Delcambre Week 5/12/2009 1

Introduction to Python, Cplex and Gurobi

Decision Structures CSC1310. Python Programming, 2/e 1

Short, Unique and Mysterious

mith College Computer Science Week 12 CSC111 Spring 2018 Dominique Thiébaut

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Python for Non-programmers

Lists, loops and decisions

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

Writing Python Programs, Numerical Data Types

Lab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han

Table of Contents EVALUATION COPY

Lecture 4: Basic I/O

Introduction to Python! Lecture 2

Decisions, Decisions. Testing, testing C H A P T E R 7

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark]

Functions: Decomposition And Code Reuse

Computing with Numbers Zelle - Chapter 3

CSI33 Data Structures

Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

PYTHON. Varun Jain & Senior Software Engineer. Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT. CenturyLink Technologies India PVT LTD

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

Some material adapted from Upenn cmpe391 slides and other sources

Python: common syntax

Intro. to Computing. Lecture 7 Page1

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability

JavaScript Basics. The Big Picture

Introduction to Python

SI Networked Computing: Storage, Communication, and Processing, Winter 2009

Python for ArcGIS. Lab 1.

Introduction to Python Code Quality

Senthil Kumaran S

A lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Session 3: JavaScript - Structured Programming

Key Differences Between Python and Java

Ch.2: Loops and lists

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Python Evaluation Rules

Use of Python in the command file. code_aster, Salome-Meca course material GNU FDL licence (

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

Loop structures and booleans

Scripting Languages. Python basics

FUNCTION PARAMETER AND ARGUMENT

Transcription:

University of Michigan Deep Blue deepblue.lib.umich.edu 2009-01 SI 502 - Networked Computing: Storage, Communication, and Processing, Winter 2009 Severance, Charles Severance, C. (2008, December 19). Networked Computing: Storage, Communication, and Processing. Retrieved from Open.Michigan - Educational Resources Web site: https://open.umich.edu/education/si/si502-winter2009. <http://hdl.handle.net/2027.42/64959> http://hdl.handle.net/2027.42/64959

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 - think about how you would do the problem by hand Determine the specifcations - for a frst programming course - the specifcations are generally in the assignment handout

Software Development Create a Design - In the beginning this is an outline of the major steps Implement the design - build your software Test and debug the program - make sure to think about different things which might go wrong Maintain the program

# convert.py # A program to convert Celsius temps to Fahrenheit# by: Susan Computewell def main(): celsius = input("what is the Celsius temperature? ") fahrenheit = (9.0 / 5.0) * celsius + 32 print "The temperature is", fahrenheit, "degrees Fahrenheit. main() Input Process Output Z-28

Running the Program... $ python convert.py What is the Celsius temperature? 0 The temperature is 32.0 degrees Fahrenheit. $ python convert.py What is the Celsius temperature? 100 The temperature is 212.0 degrees Fahrenheit. Input Process Output

Variable Names / Identifers Must start with a letter or underscore _ Must consist of letters and numbers Case Sensitive Good: spam eggs spam23 Bad: 23spam #sign var.12 Different: spam Spam SPAM Z-2.3.1

Reserved Words You can not use reserved words as variable names / identifers and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print Z-2.3.1

Expressions Programming languages have lots of expressions Expressions are things that can be evaluated to a value Can be a string, number or virtually anything Can be a single value or computed from several values using operators Z-2.3.2

Expressions Everywhere celsius = input( "What is the Celsius temperature? " ) fahrenheit = (9.0 / 5.0) * celsius + 32 print "The temperature is", fahrenheit, "degrees Fahrenheit." Z-2.3.2

Expressions with Numbers Look up variables x 0.6 Do math operations in order left to right ( ) * / 0.6 0.6 3.9 * x * ( 1 - x ) 0.4 + - 0.93 Z-2.3.2

Expressions With Strings abc Bob For strings the + operator means concatenate Bob Hello + there + abc Hello there Bob Z-4.1

Output Statements The print statement takes one or more expressions separated by commas and prints the expressions on the output separated by spaces x = 6 print 2 print 2 + 3 print Hello, 4+5 2 5 Hello 9 Z-2.4

Assignment Statements variable = expression Evaluate the expression to a value and then put that value into the variable x = 1 spam = 2 + 3 spam = x + 1 x = x + 1

Slow Motion Assignment We can use the same variable on the left and right side of an assignment statement Remember that the right side is evaluated *before* the variable is updated Z-34

Input Statements input( Prompt ) - displays the prompt and waits for us to input an expression - this works for numbers In Chapter 4 we will see how to read strings >>> x = input("enter ") Enter 123 >>> print x 123 Z-34

Simultaneous Assignment variable, variable = expression, expression Both expressions on right hand side are evaluated before the right hand side variables are updated >>> x = 1 >>> y = 2 >>> x, y = y, x >>> print x, y 2 1 >>> x, spam = 2 + 3, hello Z-36

Defnite Loops

Defnite Loops Loops that run a fxed (aka defnite) number of times Loops that iterate through an ordered set Loops that run for a number of times for abc in range(5) : print Hi print abc Hi 0 Hi 1 Hi 2 Hi 3 Hi 4 Z-39

Defnite Loops Loops that run a fxed (aka defnite) number of times Loops that iterate through an ordered set Loops that run for a number of times The iteration variable change for each iteration of the loop for abc in range(5) : print Hi print abc Colon (:) defines the start of a block. Indenting determines which lines belong to the block. Hi 0 Hi 1 Hi 2 Hi 3 Hi 4 Z-39

Looking at In... The iteration variable iterates though the sequence (ordered set) Iteration variable Five-element sequence [ 0, 1, 2, 3, 4] The block (body) of code is executed once for each value in the sequence for abc in range(5) :... block of code... The iteration variable moves through all of the values in the sequence

In a FlowChart The iteration variable iterates though the sequence (ordered set) The block (body) of code is executed once for each value in the sequence The iteration variable moves through all of the values in the sequence

i = 0 print i Program: for i in range(4) : print i i = 1 print i i = 2 print i Loop body is run repeatedly i = 3 print i

Z-40 What is range(10)? range(10) is a built in function that returns a sequence of numbers The for statement can iterate through any sequence A sequence can have values of different types >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> for i in [0, 1, 2] :... print I... 0 1 2 >>> for i in [0, "abc", 9, 2, 3.6] :... print I... 0 abc 9 2 3.6

Summary Software Development Input Processing Output Pattern Variable Names / Identifers What are legal identifers Which identifers are unique Assignment Statements Input Statements Simultaneous Assignments Definite Loops Sequences Reserved Words Expressions Output Statements