CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March 2011. Overview/Questions

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

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Python Programming: An Introduction to Computer Science

Introduction to Python

Python Programming: An Introduction to Computer Science

A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming

Welcome to Introduction to programming in Python

Objectives. Python Programming: An Introduction to Computer Science. Lab 01. What we ll learn in this class

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

CS 40 Computing for the Web

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Introduction to Python

CS 100 Introduction to Computer Science Lab 1 - Playing with Python Due September 21/23, 11:55 PM

Android: Setup Hello, World: Android Edition. due by noon ET on Wed 2/22. Ingredients.

1001ICT Introduction To Programming Lecture Notes

Computer Science 217

Practical Programming, 2nd Edition

Introduction to Python

Python for Series 60 Platform

Introduction to Java

Lab 0 (Setting up your Development Environment) Week 1

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

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

Exercise 4 Learning Python language fundamentals

Introduction to Python

STEP 0: OPEN UP THE PYTHON EDITOR. If python is on your computer already, it's time to get started. On Windows, find IDLE in the start menu.

How To Run A Hello World On Android (Jdk) On A Microsoft Ds.Io (Windows) Or Android Or Android On A Pc Or Android 4 (

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

CS 51 Intro to CS. Art Lee. September 2, 2014

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

How to write a design document

LEARNING TO PROGRAM WITH PYTHON. Richard L. Halterman

A Java Crib Sheet. First: Find the Command Line

CS 1133, LAB 2: FUNCTIONS AND TESTING

Programming Project 1: Lexical Analyzer (Scanner)

Introduction to Computers and Programming

Code Estimation Tools Directions for a Services Engagement

MEAP Edition Manning Early Access Program Hello! ios Development version 14

Using Karel with Eclipse

Netbeans IDE Tutorial for using the Weka API

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

#820 Computer Programming 1A

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Integrating Secure FTP into Data Services

IBM SPSS Statistics for Mac OS Installation Instructions (Single User)

The course assumes successful completion of CSCI E-50a and CSCI E-50b, i.e. at least two semesters of programming, with a grade of C- or better.

Installing C++ compiler for CSc212 Data Structures

Mercurial. Why version control (Single users)

Sources: On the Web: Slides will be available on:

CSC230 Getting Starting in C. Tyler Bletsch

CMSC Fundamentals of Computer Programming II (C++)

GAUSS 9.0. Quick-Start Guide

Computer Programming I & II*

Introduction to UNIX and SFTP

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Hypercosm. Studio.

Java Web Start Guide

Moving from CS 61A Scheme to CS 61B Java

Witango Application Server 6. Installation Guide for OS X

Getting Started with Mplus Version 7.31 Demo for Mac OS X and Linux

Week 2 Practical Objects and Turtles

Memory Management Simulation Interactive Lab

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

River Dell Regional School District. Computer Programming with Python Curriculum

Java Programming Fundamentals

NASA Workflow Tool. User Guide. September 29, 2010

DropSend Getting Started Guide

CS 101 Computer Programming and Utilization

VB.NET Programming Fundamentals

Obj: Sec 1.0, to describe the relationship between hardware and software HW: Read p.2 9. Do Now: Name 3 parts of the computer.

Introduction to Python for Text Analysis

Lecture 5: Java Fundamentals III

Code::Blocks Student Manual

CS 103 Lab Linux and Virtual Machines

FileMaker 11. ODBC and JDBC Guide

1.2 Using the GPG Gen key Command

COMSC 100 Programming Exercises, For SP15

How to Setup and Connect to an FTP Server Using FileZilla. Part I: Setting up the server

for Android Desktop and Conduit for Mac Quick Start Guide

Introduction to Android Development. Jeff Avery CS349, Mar 2013

MayaVi: A free tool for CFD data visualization

Writing Simple Programs

Java CPD (I) Frans Coenen Department of Computer Science

Dragon Solutions. Using A Digital Voice Recorder

Python and Cython. a dynamic language. installing Cython factorization again. working with numpy

1 Installing and Running Python

A Crash Course in OS X D. Riley and M. Allen

Introduction to Java. CS 3: Computer Programming in Java

This presentation explains how to monitor memory consumption of DataStage processes during run time.

The C Programming Language course syllabus associate level

Transcription:

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic Aaron Stevens 28 March 2011 1 Overview/Questions Review: Programmability Why learn programming? What is a programming language? What is Python? 2 1

Compiled Language Source Code (Program) Compiler Machine Code Program Inputs Running Program Outputs A compiler takes source code, and produces executable machine code (stored in a file on disk). The machine code program is executed by the user. Advantage: speed at time of execution. 3 Interpreted Language Source Code (Program) Computer Running an Interpreter Outputs Inputs An interpreter takes source code as input, and then compiles each statement and executes it immediately. Advantage: portability 4 2

Introducing Python 5 Introducing Python We will experiment with the Python programming language. What is Python? A very high level interpreted language. Very clear and simple syntax. Runs an almost any computing device Windows, Linux/Unix, Mac OS X, OS/2, Amiga, Palm Handhelds, Nokia mobile phones, and any device which supports Java. You can download and install Python on your own computer for free. We will use the Jython Environment for Students Download from http://code.google.com/p/mediacomp-jes/ 6 3

Jython Environment for Students When we launch the JES, we will see this window: This is the editor for writing and saving programs. This is the command prompt 7 Experimenting with Python Some simple output statements, and a hint of arithmetic 8 4

Python Interpreted Mode Statements and instructions typed in Python s command prompt go away when we close the JES. Instead, we can type source code into the editor window, save it as its own file, and then open and run it whenever we want. 9 Saved Program Mode Type commands in editor window Save as a file with the extension.py Load program and call functions 10 5

11 Elements of Programs Keywords Special words reserved by the language. Keywords are used to perform basic computation functions, and are one of the building blocks of programs. Example: print # The word print is a Python keyword print Hello, world! 12 6

Elements of Programs Comments Comments are lines of source code which are ignored by the Python interpreter. Comments always begin with the # mark. Example: # The word print is a Python keyword print Hello, world! 13 Elements of Programs Functions Functions are pre-written groups of instructions that we can call upon in our programs (or at the command prompt). Example: ord(<character>), chr(<integer>) 14 7

Some JES functions Examples: pickafile() makepicture(<file>) show(<picture>) 15 Variables A variable is a spot in memory which can hold a value. The value is stored using a name we chose. We can recall it when needed to use the value, or change it to hold something else. x = 42 16 8

Elements of Programs Identifiers Programmers use names to identify modules (e.g. hello.py), functions (e.g. main), and variables (e.g. pesos) within programs. Variables Give names to values within programs 17 Identifier Naming Rules Identifiers in Python follow these rules: Must begin with a letter or underscore _ May contain letters, numbers, underscores May not contain spaces, punctuation, etc. May not be Python keywords Are case sensitive x x1 dollars dollarsandcents dollars_and_cents main 9thValue print hello there my.favorite.letter 18 9

Saved Program Mode Type commands in editor window Save as a file with the extension.py Load program and call functions 19 Elements of Programs Expressions Any statement which produces a value. Values can be numeric, text, or other types. Variables, too are expressions. Examples (each line is a valid Python statement): x = 42 name = requeststring( Enter your name: ) 20 10

Arithmetic Operators Python built-in numeric operators: + addition - subtraction * multiplication / division ** exponentiation % remainder (modulo) The order of operations is the familiar PEMDAS. 21 Arithmetic Examples Build a simple calculator program 22 11

Data Types All data stored by a computer has a type. The type determines how the computer should interpret the bits in its memory. For example, we ve already dealt with both numeric data (x = 5) and non-numeric data (name = Monty ). type(x) -- returns the data type for the variable x 23 Creating our own functions For anything more than one or two commands, we ll want to create our own functions. Example: 24 12

Function Parameters A parameter is like a changeable input to a function. Example: 25 What You Learned Today Introducing Python Jython Environment for Students Command Prompt, Source code editor Print statement, literals, variables, comments Using Functions in JES 26 13

Announcements and To Do List Download & install JES on your computer! http://code.google.com/p/mediacomp-jes/downloads/list (pick 4.3 -- Mac or Windows) Readings: The CS101 Guide to Python/JES http://www.cs.bu.edu/courses/cs101b1/jes/ Optional (free) book about Python: How to Think Like A Computer Scientist: Learning with Python Available online at: http://openbookproject.net//thinkcspy/ HW9 is due Wednesday 3/30 27 14