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



Similar documents
CS 106 Introduction to Computer Science I

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

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

Moving from CS 61A Scheme to CS 61B Java

Introduction to Object-Oriented Programming

Introduction to Java

Introduction to Python

Introduction to Python

Exploring Algorithms with Python

Install Java Development Kit (JDK) 1.8

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Chapter 2 Introduction to Java programming

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Introduction to Java. CS 3: Computer Programming in Java

Using Files as Input/Output in Java 5.0 Applications

AP Computer Science Java Subset

Some programming experience in a high-level structured programming language is recommended.

Chapter 3. Input and output. 3.1 The System class

LAB4 Making Classes and Objects

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

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

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

Lecture 5: Java Fundamentals III

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

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

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

The C Programming Language course syllabus associate level

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

Chapter 2: Elements of Java

Introduction to Python

Python Programming: An Introduction to Computer Science

Introduction to Python

Exercise 1: Python Language Basics

Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13

Welcome to Introduction to Computers and Programming Course using Python

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.

Crash Course in Java

Object Oriented Software Design

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

Java Basics: Data Types, Variables, and Loops

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

ESPResSo Summer School 2012

An Overview of Java. overview-1

13 File Output and Input

Computer Programming Tutorial

CS 40 Computing for the Web

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Object Oriented Software Design

AP Computer Science Static Methods, Strings, User Input

Java Crash Course Part I

Computer Science 1 CSci 1100 Lecture 3 Python Functions

Course Intro Instructor Intro Java Intro, Continued

Java Programming Fundamentals

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

Programming Languages CIS 443

Basic Programming and PC Skills: Basic Programming and PC Skills:

Chapter 1 Java Program Design and Development

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

Beyond the Mouse A Short Course on Programming

CS 111 Classes I 1. Software Organization View to this point:

Chapter One Introduction to Programming

Sample CSE8A midterm Multiple Choice (circle one)

Python Programming: An Introduction to Computer Science

Week 1: Review of Java Programming Basics

Introduction to Programming

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Syllabus for CS 134 Java Programming

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Computer Science III Advanced Placement G/T [AP Computer Science A] Syllabus

Python for Rookies. Example Examination Paper

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

Basics of Java Programming Input and the Scanner class

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Python Programming: An Introduction to Computer Science

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Visual Basic Programming. An Introduction

AP Computer Science Java Mr. Clausen Program 9A, 9B

Informatica e Sistemi in Tempo Reale

Programmierpraktikum

Programming in Java Course Technology, a part of Cengage Learning.

PHP Tutorial From beginner to master

Computer Programming I

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

6.1. Example: A Tip Calculator 6-1

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

Python 3 Programming. OCR GCSE Computing

ECE 341 Coding Standard

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright /6/11 12:33 PM!

6.170 Tutorial 3 - Ruby Basics

Teaching an Introductory Computer Science Sequence with Python

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

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

Object-Oriented Programming in Java

C++ Programming Language

COMPUTER SCIENCE (5651) Test at a Glance

Transcription:

Practical Computer Science with Preview Background Why? Getting Our Feet Wet Comparing to Resources (Including a free textbook!) James M. Allen Hathaway Brown School jamesallen@hb.edu Background Hathaway Brown School PreK-12 All Girls School in Shaker Heights Students excel in math and science CS classes have had low enrollment Background Intro CS Course Drawing upon CSTA s Model Curriculum, Level 2 Pick a Programming Language! http://blog.i.ndigo.com.br/ 1

is simple. Why? public class HelloWorld { public static void main(string[] args) { System.out.println("Hello, World!"); print("hello, world!") is powerful. Why? Standard libraries include: Audio manipulation BSD socket library HTTP/SSL/FTP/IMAP helper modules Cryptography modules Turtle graphics is widely used. Why? is free. Why? http://wiki.python.org/moin/organizationsusing Why? It s simple. It s powerful. It s widely-used. It s free. It s fun! DEMO: PYTHON THE CALCULATOR 2

The Shell The shell is a live command-line way to run code. It can be used like a calculator Or you can even write quick, one-off programs in it Syntax A line is a line of code there is no ending punctuation. Indentation matters! Id Indents are used in lieu of curly braces to indicate idi blocks of code. is one of the most readable languages because good style is enforced. Variables To create a variable in, you simply put a variable name to the left of an = sign and put something into it. Variables are actually strongly-typed, typed but their types can change at any point in a program. Strings Strings in can look like the following: 'In apostrophes,' "in quotation ti marks," """or in triple quotes, spread out over more than one line.""" Strings Strings can be manipulated using arithmetic operators or string methods. The % operator allows string-formatting similar to sprintf() Input/Output Standard output: print() Standard input: input() 3

Comments Comments in are anything on a line following a # symbol. DEMO: MAD LIBS Madlibs.py story = '''The %s man entered the %s building to visit a %s man. "Sit down, Mr. %s. Can I interest you in any %s %s?"''' adj1 = input("adjective: ") adj2 = input("adjective: ") adj3 = input("adjective: ") lastname = input("last name: ") adj4 = input("adjective: ") noun1 = input("plural noun: ") print(story % (adj1, adj2, adj3, lastname, adj4, noun1)) Functions Functions in start with the def keyword, have parentheses containing paramaters, and a colon at the end of the line followed by an indented code block. def say_hello(person): print("hello, %s, nice to meet you!" % (person)) Modules DEMO: AREA OF A TRIANGLE Modules are brought into using the import keyword. There are many modules included with, and there are many more freely available. Game Development: Pygame GUI: PyGtk, PyQt, TkInter Image Manipulation: PIL Compilation : Py2exe, Py2app Web Development: Django, Pylons 4

vs. DEMO: PLAYING WITH TURTLES Compiled language Cross-platform Statically typed Strongly typed High-level data structures must be imported Data encapsulation (private) Some variables are objects, some are primitives Interpreted language Cross-platform Dynamically y typed Strongly typed High-level data structures are built-in No data encapsulation Everything is an object http://pythonconquerstheuniverse.wordpress.com Hello World vs. vs. Number string conversion and comparison public class HelloWorld { public static void main(string[] args) { System.out.println("Hello, World!"); int n = 0; String s = String.valueOf(n); if (s.equals("0")) { System.out.println("Equal!"); n = 0 s = str(n) if (s == "0"): print("equal!") print("hello, world!") vs. vs. Print integers from 1-100 Read numbers from a file and compute the average. for (int i = 1; i <= 100; i++) { System.out.println(i); for i in range(101): print(i) try { Scanner sc = new Scanner(new File("numbers.txt")); double total = 0; int items = 0; while (sc.hasnextdouble()) { total += sc.nextdouble(); items++; double average = total / items; catch (IOException e) { System.out.println("File Error"); myfile = open("numbers.txt") data = myfile.readlines() myfile.close() total = 0 for d in data: total = total + d average = total / len(data) 5

vs. Add numbers to a list, sort them, and output using a custom separator. ArrayList<Integer> t = new ArrayList<Integer>( Arrays.asList(7, 3, 15)); Collections.sort(t); Iterator i = t.iterator(); while (i.hasnext()) { System.out.print(i.next()); if (i.hasnext()) { System.out.print(" and "); t = [7, 3, 15] t.sort() print(" and ".join(map(str, t))) vs. Object for latitude/longitude coordinates. public class Coord { private float latitude; private float longitude; public Coord() { public Coord(float lat, float lon) { this.latitude = lat; this.longitude = lon; public float getlatitude() { return latitude; public float getlongitude() { return longitude; public void setlatitude(float lat) { this.latitude = lat; public void setlongitude(float lon) { this.longitude = lon; class Coord(object): def init (self, lat = 0, lon = 0): self.latitude = lat self.longitude = lon Resources Built-in documentation (F1) Think by Allen B. Downey http://www.greenteapress.com/thinkpython/thinkpython.html Google Questions? E-mail me: jamesallen@hb.edu 6