Course Overview, Python Basics

Similar documents
Lecture 1: Introduction, Types & Expressions

Lecture 1. Course Overview, Python Basics

Lecture 1. Course Overview, Python Basics

Lecture 1. Types, Expressions, & Variables

Lecture 1. Course Overview Types & Expressions

Lecture 2: Variables & Assignments

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

Lecture 2. Variables & Assignment

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

CS1110 Lab 1 (Jan 27-28, 2015)

CS1 Lecture 2 Jan. 16, 2019

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CS1 Lecture 3 Jan. 18, 2019

Lecture 3. Input, Output and Data Types

CPS122 Lecture: From Python to Java

Unit 7: Algorithms and Python CS 101, Fall 2018

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Intro. Scheme Basics. scm> 5 5. scm>

cs1114 REVIEW of details test closed laptop period

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

CS 115 Lecture 4. More Python; testing software. Neil Moore

T H E I N T E R A C T I V E S H E L L

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

CSE 115. Introduction to Computer Science I

Introduction to Nate Foster Spring 2018

CS/ENGRD 2110 FALL 2018

CS 1110, LAB 10: ASSERTIONS AND WHILE-LOOPS 1. Preliminaries

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

CS 1110, LAB 1: PYTHON EXPRESSIONS.

Lecture 3: Functions & Modules

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

CS Lecture 19: Loop invariants

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

WELCOME! (download slides and.py files and follow along!) LECTURE 1

Iteration and For Loops

Introduction to: Computers & Programming: Review prior to 1 st Midterm

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

CS1 Lecture 3 Jan. 22, 2018

These are notes for the third lecture; if statements and loops.

WELCOME TO CS 16! Enrollment status: 117/ Problem Solving with Computers-I

CS 1110, LAB 3: STRINGS; TESTING

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Programming for Engineers in Python. Recitation 1

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

Maxime Defauw. Learning Swift

Algorithms and Programming I. Lecture#12 Spring 2015

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

CSCE 110 Programming I

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

COMP 122/L Lecture 1. Kyle Dewey

Basic data types. Building blocks of computation

Lecture 11: Iteration and For-Loops

(Refer Slide Time 6:48)

Practical Programming, Third Edition

CS 1110: Introduction to Computing Using Python Loop Invariants

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

CMSC 201 Computer Science I for Majors

ENGR 102 Engineering Lab I - Computation

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

Full file at

PREPARING FOR PRELIM 1

CS/ENGRD 2110 SPRING 2018

Conditionals & Control Flow

Programming with Python

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

Introduction to Python and programming. Ruth Anderson UW CSE 160 Winter 2017

Variables and Data Representation

Please write your name and username here legibly: C212/A592 6W2 Summer 2017 Early Evaluation Exam: Fundamental Programming Structures in Java

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Introduction to Programming, Aug-Dec 2008

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

CS Lecture 18: Card Tricks. Announcements. Slides by D. Gries, L. Lee, S. Marschner, W. White

Shadows in the graphics pipeline

Introduction to the C++ Programming Language

The type of all data used in a C (or C++) program must be specified

CS240: Programming in C

printf( Please enter another number: ); scanf( %d, &num2);

CS 64 Week 0 Lecture 1. Kyle Dewey

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

Programming for Engineers in Python. Autumn

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

CS/ENGRD 2110 SPRING 2019

CSCI 136 Data Structures & Advanced Programming. Spring 2018 Instructors Bill Jannen & Jon Park

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

CS/ENGRD 2110 SPRING 2019

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

Welcome to CS61A! Last modified: Thu Jan 23 03:58: CS61A: Lecture #1 1

Midterms Save the Dates!

CS 142 Style Guide Grading and Details

TA hours and labs start today. First lab is out and due next Wednesday, 1/31. Getting started lab is also out

[301] Introduction. Tyler Caraza-Harter

Transcription:

CS 1110: Introduction to Computing Using Python Lecture 1 Course Overview, Python Basics [Andersen, Gries, Lee, Marschner, Van Loan, White]

Interlude: Why learn to program? (which is subtly distinct from, although a core part of, computer science itself) From the Economist: Teach computing, not Word http://www.economist.com/blogs/babbage/2010/08/computing_schools Like philosophy, computing qua computing is worth teaching less for the subject matter itself and more for the habits of mind that studying it encourages. The best way to encourage interest in computing in school is to ditch the vocational stuff that strangles the subject currently, give the kids a simple programming language, and then get out of the way and let them experiment. For some, at least, it could be the start of a life-long love affair. 1/26/17 Overview, Types & Expressions 2

Interlude, continued That, for me, sums up the seductive intellectual core of computers and computer programming: here is a magic black box. You can tell it to do whatever you want, within a certain set of rules, and it will do it; within the confines of the box you are more or less God, your powers limited only by your imagination. But the price of that power is strict discipline: you have to really know what you want, and you have to be able to express it clearly in a formal, structured way that leaves no room for the fuzzy thinking and ambiguity found everywhere else in life The sense of freedom on offer - the ability to make the machine dance to any tune you care to play - is thrilling. 1/26/17 Overview, Types & Expressions 3

CS1110 can take you places Benjamin Van Doren, a CALS student who learned to program as a freshman in CS1110 Spring 2013, helped create the dataset for a paper he co-authored that won Best Paper Award at the Computational Sustainability track at AAAI 2013. The paper title was, "Approximate Bayesian Inference for Reconstructing Velocities of Migrating Birds from Weather Radar". Van Doren has been a bird lover since third grade and was a finalist in the Intel Science Talent Search. 1/26/17 Overview, Types & Expressions 4

About Your Instructor: Prof. Andersen He works on: Educational technology Games for learning! 1/26/17 Overview, Types & Expressions 5

About Your Instructor: Prof. Lee Fellow of the Association for the Advancement of Artificial Intelligence (AAAI) What language distinguishes memorable movie quotes? NPR s All Things Considered, The Today Show (2012) 1/26/17 Overview, Types & Expressions 6

Why should you take this class? Source: Google 1/26/17 Overview, Types & Expressions 7

Why should you take this class? Outcomes: Fluency in (Python) procedural programming Usage of assignments, conditionals, and loops Ability to create Python modules and programs Competency in object-oriented programming Ability to recognize and use objects and classes Knowledge of searching and sorting algorithms Knowledge of basics of vector computation 1/26/17 Overview, Types & Expressions 8

Intro Programming Classes Compared CS 1110: Python No prior programming experience necessary No calculus Slight focus on Software engineering Application design CS 1112: Matlab No prior programming experience necessary One semester of calculus Slight focus on Scientific computation Engineering applications But either course serves as a pre-requisite to CS 2110 1/26/17 Overview, Types & Expressions 9

Why Python? Python is easier for beginners A lot less to learn before you start doing Designed with rapid prototyping in mind Python is more relevant to non-cs majors NumPy and SciPy heavily used by scientists Python is a more modern language Popular for web applications (e.g. Facebook apps) Also applicable to mobile app development 1/26/17 Overview, Types & Expressions 10

Course Website www.cs.cornell.edu/courses/cs1110/2017sp/ LOOK FOR THE SPRING 2017 BAT!!! If no bat, you are looking at the wrong year 1/26/17 Overview, Types & Expressions 11

Communication cs-1110profs-l@cornell.edu Includes: two profs, admin assistant Main correspondence. Don t email only one prof, or both separately cs-1110mgmt-l@cornell.edu Includes: both profs, admin assistant, graduate TAs, head consultants Emergency contact number. nobody at office hours; lab has no printouts Email from us: please check your spam filters for mail from ELA63@cornell.edu, LJL2@cornell.edu, or with [CS1110] in the subject line. 1/26/17 Overview, Types & Expressions 12

ACCEL Labs Enter from front Walk to staircase on left Go up the stairs 1/26/17 Overview, Types & Expressions 13

Class Structure Lectures. Every Tuesday/Thursday Not just slides; interactive demos almost every lecture Discussion Sections = Labs. Guided exercises with TAs and consultants helping out Handouts posted to the website the Monday before Don t panic if you are not registered yet. Go to the lab section you are registered for. If not enrolled in a lab section: do the lab on your own. If a lab section opens up, check it in then. Mandatory. Missing more than 2 can lower your final grade. 1/26/17 Overview, Types & Expressions 14

Class Materials Textbook. Think Python by Allen Downey Supplemental text; does not replace lecture Book available for free as PDF or ebook (no hard copy anymore; out of print) iclicker. Optional but useful. Will periodically ask questions during lecture Not part of the grade at all Python. Necessary if you want to use own computer See course website for how to install the software 1/26/17 Overview, Types & Expressions 15

Things to Do Before Next Class 1. Read the textbook Chapter 1 (browse) Chapter 2 (in detail) 2. Install Python following our instructions: http://www.cs.cornell.edu/courses/cs1 110/2017sp/materials/python.php 3. Look at first lab handout 4. (optional) Piazza: a question-answering forum Everything is on website! Piazza instructions Class announcements Consultant calendar Reading schedule Lecture slides Exam dates Check it regularly: www.cs.cornell.edu/ courses/cs1110/2017sp/ 1/26/17 Overview, Types & Expressions 16

Getting Started with Python Designed to be used from the command line OS X/Linux: Terminal Windows: Command Prompt Purpose of the first lab CORRECT: Once installed type python Starts an interactive shell Type commands at >>> Shell responds to commands Can use it like a calculator This class uses Python 2.7.x WRONG: Use to evaluate expressions 1/26/17 Overview, Types & Expressions 17

Values Much of Python is storing and computing data What data values might we want to work with? Numbers 42 3.0 * 10 8 0.00001 Text apple pineapple Truth True False 1/26/17 Overview, Types & Expressions 18

Expressions An expression represents something Python evaluates it (turns it into a value) Similar to a calculator Examples: 2.3 Literal (evaluates to self) (3 * 7 + 2) * 0.1 An expression with four literals and some operators 1/26/17 Overview, Types & Expressions 19

Types A set of values, and operations on these values. Examples of operations: +, -, /, * The meaning of each operation depends on the type Memorize this definition! 1/26/17 Overview, Types & Expressions 20

How To Tell The Type of a Value Command: type(<value>) Example: >>> type(2) <type 'int'> 1/26/17 Overview, Types & Expressions 21

Example: Type int Type int represents integers values:, 3, 2, 1, 0, 1, 2, 3, 4, 5, Examples 1 45 43028030 no commas or periods operations: +,, *, /, **, unary, % multiply to power of remainder 1/26/17 Overview, Types & Expressions 22

Operations on ints Operations on int values must yield an int Examples: 2 + 2 result: 4 4 / 7 result: 0 This is confusing at first! Then becomes natural. Companion to / (division) is % (remainder) Examples: 1 / 2 = 0 1 % 2 = 1 (remainder when dividing 1 by 2) 1/26/17 Overview, Types & Expressions 23

Example: Type float Type float represents real numbers float is short for floating point values: distinguished from integers by decimal points In Python a number with a. is a float literal (e.g. 2.0) Without a decimal a number is an int literal (e.g. 2) operations: +,, *, /, **, unary The meaning for floats differs from that for ints Example: 1.0/2.0 evaluates to 0.5 Exponent notation is useful for large (or small) values 22.51e6 is 22.51 * 10 6 or 22510000 22.51e 6 is 22.51 * 10 6 or 0.00002251 A second kind 1/26/17 of float literal Overview, Types & Expressions 24

Floating Point Errors Python stores floats as binary fractions Integer mantissa times a power of 2 Example: 1.25 is 5 * 2 2 mantissa exponent Impossible to write most real numbers this way exactly Similar to problem of writing 1/3 with decimals Python chooses the closest binary fraction it can This approximation results in representation error When combined in expressions, the error can get worse Example: type 0.1 + 0.2 at the prompt >>> 1/26/17 Overview, Types & Expressions 25

Example: Type bool Type boolean or bool represents logical statements values: True, False Boolean literals are just True and False (have to be capitalized) operations: not, and, or not b: True if b is false and False if b is true b and c: True if both b and c are true; False otherwise b or c: True if b is true or c is true; False otherwise Often come from comparing int or float values Order comparison: i < j i <= j i >= j i > j Equality, inequality: i == j i!= j "=" means something else! 1/26/17 Overview, Types & Expressions 26

Boolean Misconceptions Boolean expressions sound similar to English However, subtle differences lead to mistakes: In English, A = B and C often means A = B and A = C Example: Ithaca is cold and snowy Means: Ithaca is cold and Ithaca is snowy Does not mean: Ithaca is cold and. snowy Python requires you to fully specify Boolean operations In English, A or B often means A or B but not both Example: I will take CS 1110 or CS 1112 (but not both) In Python, A or B always means A or B or both 1/26/17 Overview, Types & Expressions 27

Example: Type str Type String or str represents text values: any sequence of characters operation(s): + (catenation, or concatenation) String literal: sequence of characters in quotes Double quotes: " abcex3$g<&" or "Hello World!" Single quotes: 'Hello World!' Concatenation can only apply to strings. 'ab' + 'cd' evaluates to 'abcd' 'ab' + 2 produces an error 1/26/17 Overview, Types & Expressions 28