You Need an Interpreter! Comp Spring /28/08 L10 - An Interpreter

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

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Flow Control: Branches and loops

Molecular Statistics Exercise 1. As was shown to you this morning, the interactive python shell can add, subtract, multiply and divide numbers.

Python is available at: Why Python is awesome:

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

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Intro to Python & Programming. C-START Python PD Workshop

Basic Python 3 Programming (Theory & Practical)

Programming Fundamentals and Python

An Introduction to Python

Introduction to Python (All the Basic Stuff)

Computer and Programming: Lab 1

Unit 7: Algorithms and Python CS 101, Fall 2018

Table of Contents EVALUATION COPY

Semester 2, 2018: Lab 1

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

Introduction to Python

Python Problems MTH 151. Texas A&M University. November 8, 2017

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

Python Programming Exercises 3

CSCI 121: Anatomy of a Python Script

Creating Reports. There are several types of reports. We'll use Access Wizards and Tabs/Ribbons to design several simple reports.

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

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

Invent Your Own Computer Games with Python

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

What Version Number to Install

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

Seagate Crystal Reports 8 and Hyperion Essbase

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Introduction to Programming with Python 3, Ami Gates. Chapter 1: Creating a Programming Environment

nostarch.com/pfk For bulk orders, please contact us at

Part 6b: The effect of scale on raster calculations mean local relief and slope

Lists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists

MEIN 50010: Python Introduction

COM110: Lab 2 Numeric expressions, strings, and some file processing (chapters 3 and 5)

ASCII Art. Introduction: Python

Exploring Python Basics

C H A P T E R 1. Introduction to Computers and Programming

Track Changes in MS Word

Exploring Python Basics

S206E Lecture 19, 5/24/2016, Python an overview

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

CS Prof J.P.Morrison

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Algorithms and Programming I. Lecture#12 Spring 2015

Lab 2: input(), if else, String Operations, Variable Assignment. Ling 1330/2330: Computational Linguistics Na-Rae Han

A Brief Introduction of how to use Audacity

Week - 01 Lecture - 04 Downloading and installing Python

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

Python for ArcGIS. Lab 1.

Lecture 1. basic Python programs, defining functions

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Part III Appendices 165

10 things you should know about Word 2010's mail merge tools

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

The current topic: Python. Announcements. Python. Python

Variables, expressions and statements

Python Day 3 11/28/16

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

Python Programming Exercises 1

PROGRAMMING FUNDAMENTALS

Using IDLE for

Student Database Challenge Problem

CS1110 Lab 1 (Jan 27-28, 2015)

The >>> is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

Python Input, output and variables

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

UTEXAS Embankment on Soft Clay

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

5/20/2007. Touring Essential Programs

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Creating Word Outlines from Compendium on a Mac

Text Input and Conditionals

ECS15, Lecture 14. Reminder: how to learn Python. Today is the final day to request a regrade of the midterm. Topic 4: Programming in Python, cont.

OOP and Scripting in Python Advanced Features

To see how ARP (Address Resolution Protocol) works. ARP is an essential glue protocol that is used to join Ethernet and IP.

Masternode Setup Guide. HexCash Coin. Masternode Setup Guide Version /

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 4. Unix Tutorial. Unix Shell

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

v. 9.1 GMS 9.1 Tutorial UTEXAS Embankment On Soft Clay Introduction to the UTEXAS interface in GMS for a simple embankment analysis

How to export data from Reckon Quicken Personal Plus to Moneydance By Michael Young

Getting Started with Python

Some Handy Computing and Graphing Tools

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman

18.1. CS 102 Unit 18. Python. Mark Redekopp

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Python for Informatics

Communication Process (1)

Introduction to Programming

HRS-9 Data Slice Editing and Math. Jon Brown 2013

Chapter 2 The SAS Environment

Transcription:

You Need an Interpreter!

Closing the GAP Thus far, we ve been struggling to speak to computers in their language, maybe its time we spoke to them in ours How high can we rasie the level of discourse? We ll enlist the aid of an interpreter An interpreted language uses the computer to do all the hard work of figuring out what is meant by a statement. It figures out what instructions to execute, where variables are stored, and how best to accomplish the goals of the program given a high-level specification

A Quick Class Exercise Download Python 2.5 (www.python.org/download) Most of you will click on the Windows Installer Select the defaults and install on your machine Now choose Python (command line) from your start menu

Getting Started Type the following commands at the >>> prompt After entering a couple of commands, try using the up-arrow key to bring back an old command

Feeling Loopy? Let s write a simple loop to repeat a command several times Enter a tab to set off the body of the loop, which is the part that gets repeated. Type a return at the end of the body.

One More For You A second type of loop specifies a range of values for a variable to take on Why did it just go to 9?

What s in a Range A Range generates a list of values to set a variable to. Three versions range(whilelessthan) # starts at 0 range(first, whilelessthan) range(first, whilelessthan, step)

Or Make your own List A for loop will replace the variable with the items from any user-specified list Lists can hold numbers, strings, or variables

No Strings Attached Variables can be set to a sequence of characters called strings Python provides many ways of processing strings Strings can be indexed x[0] to access characters (the first character is 0) Strings can be sliced x[2:7] to get a range of characters

You ve seen range() Loops with Strings Another built in function is len()

A Function Let s try some simple user-defined functions Two levels of indention. One for the body of the function, another for the subbody of the for loop Functions can call other functions

More Math By default, integer arithmetic is used on integers (might lead to unexpected results) More functions

More Lists Lists are very flexible variable types Can be indexed and sliced like strings Also, sorted, modified, shortened, an enlarged

Conditionals if/then/else allow statements to be executed conditionally Can use and and or to combine conditions

From Statements to a Program Thus far, we ve written small functions and entered simple statements into the python interpreter. At this point we ll store a list of statements in a file to create a program. Steps Create a list of statements in a file with the filename extension.py using a text editor Run the program one of 2 ways 1) Type python programname.py 2) Double click on the file

A Simple Text Editor Python provides a simple text editor called Idle Operating system also provides a simple editor (Windows XP: Notepad, Mac OSX: TextEdit) Idle + Python Aware, and thus tries to help you with your program - It does not conform to user-interface standards

Creating a File 1) On the File Menu Choose New Window 2) Type in the simple function and the following for loop Notice how Idle automatically highlights keywords 3) When finished save the file as HexDigits.py

Running the Program 1) On the Run Menu Choose Run Module or just press F5 2) The program should run in the shell window 3) You can also run it by double-clicking on the file in an explorer window

Getting User Input We used a new built in function at the end of this program called raw_input() raw_input( prompt string ) prints the prompt and then reads an input string from the user In our example we ignored the input string, but we could have saved it in a variable. Ex. x = raw_input( What is your name? ) This will allow us to write more interesting programs that interact with us

A Simple Game Let s use what we ve learned so far to write a simple number guessing game Save as YouGuess.py Run using F5

The Reverse Here s the game in reverse, where the computer tries to guess your number

A Useful Utility A simple program to count the number of lines, words, and characters in a text file Importing sys and string libraries String.split(control) splits a string into a list separated by characters from the control string. If no control string is specified, the string string.whitespace from the string library is used.

Next Time Now that we can write a script or program by saving our statements in a file We ll explore more Python We ll use Python to explore our computer Composing and importing scripts