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.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

Intro to Python Welcome to the Wonderful world of GIS programing!
Lab6 – Debug Assembly Language Lab
Java Programming Working with TextPad. Using TextPad to Work with Java This text editor is designed for working with Java You can download a trial version.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Chapter 1: Python Basics CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Game Programming © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line L.
Python Programming Fundamentals
An Introduction to Textual Programming
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Shell Script Programming
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Computational Linguistics Programming I.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Introduction to Programming Peggy Batchelor.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
 We are going to learn about programming in general…How to think logically and problem solve. The programming language we will use is Python. This is.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Python From the book “Think Python”
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 4: Writing programs.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 1 Welcome! This is Professor Jai P. Agrawal. I will walk.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
Programming Seminar 2009 Night 0. Why we’re holding this seminar You’re probably not a computer science major – Or even anything remotely close (e.g.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
1. Starting 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
Getting Started With Python Brendan Routledge
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Development Environment
CST 1101 Problem Solving Using Computers
Whatcha doin'? Aims: To start using Python. To understand loops.
Python: Experiencing IDLE, writing simple programs
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Python
Topics Introduction to Repetition Structures
Lecture 1 Introduction to Python Programming
Variables, Expressions, and IO
Basic operations in Matlab
Let's Learn Python and Pygame
Week 1 Computer Programming Year 9 – Unit 9.04
Topics Introduction Hardware and Software How Computers Store Data
BSc in Digital Media, PSUIC
A look at Python Programming Language 2018.
CS 1111 Introduction to Programming Spring 2019
Python Basics with Jupyter Notebook
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Introduction to Python
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
Presentation transcript:

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 raise 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 ( 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

One More “For” You A second type of loop specifies a range of values for a variable to take on

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

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

A Function Let’s try some simple user-defined functions 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