Unformatted text preview:

Logistics Personnel Instructor Liang Huang lhuang3 cis upenn edu Bill Kandylas kandylas cis upenn edu TA Administrator Jennifer Finley jfinley cis upenn edu Coordinates March 13 April 21 6 weeks after spring break MW 1 2 PM Towne 309 Lecture Lab Recitation F 1 2 PM Moore 207 Office Hours R 3 4 PM Levine 565 CSE 399 004 Spring 2006 Python Programming Handout 1 Lectures 1 and 2 handouts available online at www seas upenn edu cse39905 schedule html Logistics cont d Textbooks for reference Textbooks Dive into Python www seas upenn edu cse39905 Homepage schedule syllabus homework handouts etc upenn cis cse399 005 Newsgroup announcements Q A cse39905 seas Course Email to reach both the instructor and the TA courseweb library upenn edu Blackboard grades and announcements by Mark Pilgrim How to Think Like a Computer Scientist Learning Python by Allen B Downey Jeffrey Elkner and Chris Meyers by Guido van Rossum inventor of Python by Norm Matloff A Quick Painless Tutorial on the Python Language Homework 4 Grades 6 weekly programming assignments to be completed individually usually out on Mondays and due on Sundays submit your work through the turnin program late policy 24 hours 25 off 48 hours 50 off 60 Homework 10 Quiz 25 Final Exam and 5 Participation Quiz and Final Exam Both during labs on Mar 31 and Apr 21 respectively closed book but open to one Letter sheet of notes Participation Labs are optional but recommended no points afterwards input output format will be strictly enforced there will be sample I O files online we will not follow any textbook Tutorials Official Python Tutorial 3 2 we teach some additional material and help with HW you will be rewarded for catching bugs in course make sure your programs pass them before submission materials handouts textbooks homework exams otherwise you will get 0 for this problem 5 6 Before and After this course Course Outline www seas upenn edu cse39905 schedule html Before this course CSE 120 Intro to CS with Java required Two parts 3 weeks each separated by Quiz 1 Python Basics CSE 399 is not an intro to programming course CSE 121 Data Structures with Java recommended you may take it in parallel After this course CSE 391 Artificial Intelligence CIS 530 Computational Linguistics and many more to come Syntax Control Flow Data Structures Lists Dictionaries Tuples etc Regular Expressions and String Processing File I O and Exception Handling 2 Object Oriented and Functional Programming 7 OOP Objects Inheritance Linked Lists Trees etc FP map filter reduction iterator generator function 8 Why Python Because it s easy and great fun less than 10 years old yet very popular now a wide range of applications esp in AI and Web many schools have shifted their intro courses to Python much shorter code compared to C C and Java more English like syntax and a smaller semantic gap extremely easy to learn On to Python fast to write easy to read and maintain 10 Python is Hello World C include stdio h a scripting language strong in text processing interpreted like Perl but much more elegant a very high level language closer to human like Java unlike C or Assembly procedural like C Pascal Basic and many more but also object oriented like C and Java and even functional like ML Scheme Haskell etc int main int argc char argv printf Hello World n Java public class Hello public static void main String argv System out println Hello World now in Python print Hello World 11 12 Printing an Array Reversing an Array void print array char a int len int i has to specify len for i 0 i len i and only for one type char printf s n a i C for element in list print element Python for in only indentations no blocks def rev a def if a return else return rev a 1 a 0 no C style for loops or even simpler static int reverse array int a int temp new int a length for int i 0 i len i temp i a a length i 1 return temp for i 0 i 10 i or even simpler print list a reverse 13 a without a 0 Java Python no need to specify argument and return types python will figure it out dynamically typed singleton list built in list processing function 14 Quick sort public void sort int low int high if low high return int p partition low high sort low p sort p 1 high void swap int i int j int temp a i a i a j a j temp int partition int low int high int pivot a low int i low 1 int j high 1 while i j i while a i pivot i j while a j pivot j if i j swap i j return j def sort a if a x x a x pivot return else pivot a 0 left x for x in a if x pivot right x for x in a 1 if x pivot return sort left pivot sort right Take a closer look Java Python smaller semantic gap 15 Python Interpreter The right version of Python Three ways to run a Python program 1 Interactive like DrJava like Java Python is still under active development we will use the latest version 2 4 or 2 4 2 our default machine is eniac l seas upenn edu where default python is 2 3 4 for i in range 5 print i 0 1 2 3 4 2 default save to a file say foo py in command line to use the latest python on eniac l you can either python foo py 3 add a special line pointing to the default interpreter e g usr bin python at the beginning of foo py make foo py executable chmod in command line foo py x foo py python2 4 2 or append one of the following to your bashrc file best solution 17 export PATH usr local python 2 4 2 PATH alias python python2 4 2 demo 18 Install your own Python alternatively you can install python 2 4 2 on your own Windows Mac Linux machines from www python org resources page for instructions see www seas upenn edu cse39905 resources html we will help with python installations at this Friday s Basic Python Syntax Lab you can bring your laptop if you have problems bash 2 0 python Python 2 4 1 Jan 22 2005 18 59 00 GCC 3 3 20030304 Apple Computer Inc build 1495 on darwin Type help copyright credits or license for more information 19 Numbers and Strings Assignments and Comparisons like Java Python has built in atomic types numbers int float bool string list etc numeric operators a 5 b 3 a b 8 type 5 type int a 4 a 9 no i or i c 1 5 c 1 5 type c a type float 5 2 2 5 2 2 5 5 2 25 a b 0 a 0 b 0 s hey type s type str s guys …


View Full Document

Penn CIS 399 - Python Programming Handout

Download Python Programming Handout
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Python Programming Handout and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Python Programming Handout 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?