Exploring Algorithms with Python

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

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Introduction to Python

Introduction to Python

2/1/2010. Background Why Python? Getting Our Feet Wet Comparing Python to Java Resources (Including a free textbook!) Hathaway Brown School

Moving from CS 61A Scheme to CS 61B Java

Today s Topics... Intro to Computer Science (cont.) Python exercise. Reading Assignment. Ch 1: 1.5 (through 1.5.2) Lecture Notes CPSC 121 (Fall 2011)

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

CS 40 Computing for the Web

Semester Review. CSC 301, Fall 2015

GlueTrack interpreter for S2E beam dynamic simulations. Igor Zagorodnov BDGM, DESY

6.170 Tutorial 3 - Ruby Basics

Fall 2012 Q530. Programming for Cognitive Science

Introduction to the course, Eclipse and Python

CS506 Web Design and Development Solved Online Quiz No. 01

Introduction to Python

Programming Languages

CS 106 Introduction to Computer Science I

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

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

Software Development (CS2500)

Computational Mathematics with Python

Welcome to Introduction to Computers and Programming Course using Python

13 File Output and Input

The C Programming Language course syllabus associate level

Python Programming: An Introduction to Computer Science

Introduction to Python

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

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

6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang

Hands-On Python A Tutorial Introduction for Beginners Python 3.1 Version

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Chapter 3. Input and output. 3.1 The System class

Assignment 2: Option Pricing and the Black-Scholes formula The University of British Columbia Science One CS Instructor: Michael Gelbart

Computational Mathematics with Python

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Computational Mathematics with Python

Introduction to Python

Computer Science for San Francisco Youth

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

Python for Scientific Computing.

Programming Languages & Tools

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Introduction to Object-Oriented Programming

Python Programming: An Introduction to Computer Science

What is a programming language?

CSE 307: Principles of Programming Languages

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

CS346: Database Programming.

Chapter 1 Fundamentals of Java Programming

Install Java Development Kit (JDK) 1.8

Chapter 6: Programming Languages

Exercise 1: Python Language Basics

Programming Languages

Chapter 2: Elements of Java

Module 1. Internet Basics. Participant s Guide

1001ICT Introduction To Programming Lecture Notes

Objects and classes. Objects and classes. Jarkko Toivonen (CS Department) Programming in Python 1

McGraw-Hill The McGraw-Hill Companies, Inc.,

LAB4 Making Classes and Objects

Python for Rookies. Example Examination Paper

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

CS 6371: Advanced Programming Languages

Chapter 13: Program Development and Programming Languages

sveltest: A testing language

Chapter 2 Writing Simple Programs

Threads Scheduling on Linux Operating Systems

Programming Project 1: Lexical Analyzer (Scanner)

Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

The programming language C. sws1 1

Web development... the server side (of the force)

Week 2 Practical Objects and Turtles

CS 253: Intro to Systems Programming

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

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

DATA SCIENCE ADVISING NOTES David Wild - updated May 2015

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

OHIO EXPOSITIONS COMMISSION CUSTOMER SERVICE GUIDELINES

CS 378 Big Data Programming. Lecture 9 Complex Writable Types

Data Science Certificate General Information About Completion

An Incomplete C++ Primer. University of Wyoming MA 5310

Unlocking the True Value of Hadoop with Open Data Science

AppendixA1A1. Java Language Coding Guidelines. A1.1 Introduction

Centrex Messaging. User Guide

ESPResSo Summer School 2012

The first program: Little Crab

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

Java Crash Course Part I

Excel Intermediate Session 2: Charts and Tables

Installing Java (Windows) and Writing your First Program

Course Title: Software Development

Why do I have to log in as a Current UM Employee?

Transcription:

Exploring Algorithms with Python Dr. Chris Mayfield Department of Computer Science James Madison University Oct 16, 2014

What is Python? From Wikipedia: General-purpose, high-level programming language One line of code translates to many CPU instructions Design philosophy emphasizes code readability Syntax is minimal; indenting is part of the language Supports multiple programming paradigms Imperative, object-oriented, procedural, functional,... Other features: Interpreted and interactive; very easy to learn Extensive standard library ( batteries included ) Free and open source; very active community Home page: http://www.python.org/ Oct 16, 2014 Exploring Algorithms with Python 2 of 14

Who uses Python? Google (various projects) NASA (several projects) NYSE (one of only three languages on the floor ) Industrial Light & Magic (everything) Yahoo! (Yahoo mail & groups) RealNetworks (function and load testing) RedHat and Ubuntu (Linux installation tools) LLNL, Fermilab (steering scientific applications) More success stories at http://www.pythonology.com/ Oct 16, 2014 Exploring Algorithms with Python 3 of 14

Installing Python Note: We will be using Python version 2.7 (the default that currently ships with Mac/Linux) Linux / Mac: it s built in! Just run python (or idle) from the terminal Windows: Go to http://www.python.org/download/ Python 2.7.8 Windows X86-64 Installer Run python or idle from the start menu Oct 16, 2014 Exploring Algorithms with Python 4 of 14

What you need to know for CS 101 Oct 16, 2014 Exploring Algorithms with Python 5 of 14

Algorithm representation Section 5.2 presents four basic primitives: 1. Assignment name expression 2. Decisions if condition then activity if condition then activity else activity 3. Loops while condition do activity 4. Functions def name(parameters) Oct 16, 2014 Exploring Algorithms with Python 6 of 14

Example using all four def greeting ( hour ): if hour < 12: print " Good morning!" else : print " Good afternoon!" # count up to 5:00 PM now = hour while now < 18: print "It s now ", now, "o clock." now = now + 1 print " Time to eat!" # test it out greeting (9) greeting (15) NOTE: Files are executed from top to bottom The first statement defines a function The last two statements call the function Oct 16, 2014 Exploring Algorithms with Python 7 of 14

How does Python compare to other languages? In case you can t wait until next week... Oct 16, 2014 Exploring Algorithms with Python 8 of 14

Python vs Java Python Dynamically typed (bind names to values) Concise: expressing much in a few words; implies clean-cut brevity, attained by excision of the superfluous # open the file d. txt myfile = open ("d. txt ") Java Statically typed (must declare variables) Verbose: abounding in words; using or containing more words than are necessary import java.io.*;... // open the file d. txt BufferedReader myfile ; myfile = new BufferedReader ( new FileReader ("d. txt " )); http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/ Oct 16, 2014 Exploring Algorithms with Python 9 of 14

Tips for CS 139/149 students If you are currently learning Java... // Java example int x; x = 1; if (x > 0) { System. out. println ( "x is positive!"); } Forget about declarations Forget about semicolons But think about colons Forget about parentheses Forget about braces But remember to indent! # Python example x = 1 if x > 0: print " x is positive!" http://xkcd.com/353/ Oct 16, 2014 Exploring Algorithms with Python 10 of 14

Okay, so now what? Oct 16, 2014 Exploring Algorithms with Python 11 of 14

CS is a creative activity Computational thinking is a way humans solve problems; it is not trying to get humans to think like computers. Computers are dull and boring; humans are clever and imaginative. We humans make computers exciting. Equipped with computing devices, we use our cleverness to tackle problems we would not dare take on before the age of computing and build systems with functionality limited only by our imaginations; Jeannette M. Wing, Computational Thinking, CACM 2006 http://www.cs.cmu.edu/afs/cs/usr/wing/www/publications/wing06.pdf Oct 16, 2014 Exploring Algorithms with Python 12 of 14

Algorithm discovery Section 5.3 is a fantastic read: The art of problem solving Don t follow steps; take the initiative Trying examples helps you understand Let your subconscious work for you Getting a foot in the door Starting is often the hardest part Extend knowledge, reverse engineer Resist the temptation to use formulas! The more problems you solve, the more creative you become! Oct 16, 2014 Exploring Algorithms with Python 13 of 14

Loop control You don t need to read all of Section 5.4 Focus on loop control, pages 224 228 In particular, Figure 5.7 (components) # while loop example count = 3 # initialize while count > 0: # test print Hello count = count - 1 # modify # for loop example for i in range (3): # all in one print Hello Note: Python does not have a post-test loop Oct 16, 2014 Exploring Algorithms with Python 14 of 14