Lecture 1. Course Overview, Python Basics

Similar documents
Lecture 1. Course Overview, Python Basics

Lecture 1. Types, Expressions, & Variables

Course Overview, Python Basics

Lecture 1. Course Overview Types & Expressions

Lecture 1: Introduction, Types & Expressions

Lecture 2. Variables & Assignment

Lecture 2: Variables & Assignments

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

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CS 1110, LAB 1: PYTHON EXPRESSIONS.

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

CS1110 Lab 1 (Jan 27-28, 2015)

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

CS 240 Fall Mike Lam, Professor. Just-for-fun survey:

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

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

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

cs1114 REVIEW of details test closed laptop period

CS 241 Data Organization using C

CS/ENGRD 2110 FALL 2018

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

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

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

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

Announcements. 1. Forms to return today after class:

CS 241 Data Organization. August 21, 2018

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

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Full file at

CS101: Intro to Computing Summer Week 1

ENGR 102 Engineering Lab I - Computation

CS1 Lecture 3 Jan. 18, 2019

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

CIS192: Python Programming

PREPARING FOR PRELIM 1

Unit 7: Algorithms and Python CS 101, Fall 2018

Lecture 3. Input, Output and Data Types

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

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

CSE 115. Introduction to Computer Science I

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

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

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

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

CONCORDIA UNIVERSITY DEPARTMENT OF CHEMISTRY AND BIOCHEMISTRY CHEM 293 SPECTROSCOPY AND STRUCTURE OF ORGANIC COMPOUNDS. SYLLABUS Winter 2018

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Course Syllabus - CNT 4703 Design and Implementation of Computer Communication Networks Fall 2011

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

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

Basic data types. Building blocks of computation

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

Exercise: Using Numbers

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

CS1 Lecture 3 Jan. 22, 2018

Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

CIS192 Python Programming. Robert Rand. August 27, 2015

ESET 349 Microcontroller Architecture, Fall 2018

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

COMP Primitive and Class Types. Yi Hong May 14, 2015

Visual C# Instructor s Manual Table of Contents

These are reserved words of the C language. For example int, float, if, else, for, while etc.

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

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

Computer Science II Lecture 1 Introduction and Background

QUIZ: What value is stored in a after this

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

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

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

CS112 Lecture: Primitive Types, Operators, Strings

Updated: 2/14/2017 Page 1 of 6

COMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

CMSC 201 Computer Science I for Majors

Algorithms and Programming I. Lecture#12 Spring 2015

Java Fall 2018 Margaret Reid-Miller

Full file at

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

CS 235AM, Mobile Application Development: Android Spring 2016

COMP 110 Introduction to Programming. What did we discuss?

Beijing Jiaotong University CS-23: C++ Programming Summer, 2019 Course Syllabus

Unit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.

Part III Appendices 165

College Algebra. Cartesian Coordinates and Graphs. Dr. Nguyen August 22, Department of Mathematics UK

Number Representation 3/2/01 Lecture #

Fundamentals: Expressions and Assignment

Introduction to Web Design & Computer Principles

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

CS1 Lecture 2 Jan. 16, 2019

CSci 4211: Introduction to Computer Networks. Time: Monday and Wednesday 2:30 to 3:45 pm Location: Smith Hall 231 Fall 2018, 3 Credits

CS101 Lecture 04: Binary Arithmetic

Programming Studio #1 ECE 190

Lecture 0 of 41: Part A Course Organization. Introduction to Computer Graphics: Course Organization and Survey

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

Programming Languages and Techniques (CIS120)

CS240: Programming in C

ENGR 101 Engineering Design Workshop

Values, Variables, Types & Arithmetic Expressions. Agenda

Lecture 4. Defining Functions

Transcription:

Lecture 1 Course Overview, Python Basics

We Are Very Full! Lectures and Labs are at fire-code capacity We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are allowed this semester All students must do assignments Graduate students should take CS 1133 CS 1112 has plenty of room for students 8/23/16 Overview, Types & Expressions 2

About Your Instructor: Walker White Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/23/16 Overview, Types & Expressions 3

Outcomes: CS 1110 Fall 2015 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 Website: www.cs.cornell.edu/courses/cs1110/2016fa/ 8/23/16 Overview, Types & Expressions 4

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 8/23/16 Overview, Types & Expressions 5

CS 1133: Short Course in Python Catalogue lists as Transition to Python Says it requires programming experience This is a lie 1-credit course in how to use Python All the Python of 1110 without the theory Three assignments; no exams No experience required For graduate students who need Python 8/23/16 Overview, Types & Expressions 6

Why Programming in 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 8/23/16 Overview, Types & Expressions 7

Class Structure Lectures. Every Tuesday/Thursday Not just slides; interactive demos almost every lecture Because of enrollment, please stay with your section Semi-Mandatory. 1% Participation grade from iclickers Section/labs. ACCEL Lab, Carpenter 2 nd floor The overflow sections are in Phillips 318 Guided exercises with TAs and consultants helping out Tuesday: 12:20, 1:25, 2:30, 3:35 Wednesday: 10:10, 11:15, 12:20, 1:25, 2:30, 3:35, 7:20 Contact Amy (ahf42@cornell.edu) for section conflicts Mandatory. Missing more than 2 lowers your final grade 8/23/16 Overview, Types & Expressions 8

ACCEL Labs Enter from front Walk to staircase on left Go up the stairs 8/23/16 Overview, Types & Expressions 9

Class Materials Textbook. Think Python by Allen Downey Supplemental text; does not replace lecture Book available for free as PDF or ebook Hardbound copies only available online iclicker. Acquire one by next Thursday Will periodically ask questions during lecture Will get credit for answering even if wrong iclicker App for smartphone is not acceptable Python. Necessary if you want to use own computer See course website for how to install the software 8/23/16 Overview, Types & Expressions 10

This Class is OS Agnostic Windows 7 or higher 8/23/16 OS X 10.9 or higher Overview, Types & Expressions 11

The Preferred OSes Windows 10 8/23/16 OS X 10.11 Overview, Types & Expressions 12

Do NOT Even THINK It! Coming this October 8/23/16 Overview, Types & Expressions 13

Do NOT Even THINK It! Coming this October 8/23/16 Overview, Types & Expressions 14

Things to Do Before Next Class 1. Register your iclicker Does not count for grade if not registered 2. Enroll in Piazza 3. Sign into CMS Complete the Quiz Complete Survey 0 4. Read the textbook Chapter 1 (browse) Chapter 2 (in detail) 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/2016fa/ 8/23/16 Overview, Types & Expressions 15

Academic Integrity Every semester we have cases of plagiarism Claiming the work of others as your own This is an Academic Integrity violation Protect yourself by citing your sources Just like in writing a paper for freshman seminar Course website covers how and when to cite Complete Academic Integrity Quiz on CMS Must complete successfully to stay in class 8/23/16 Overview, Types & Expressions 16

A Word About About Grades As Cornell students, we know that you care But this is not a weed-out course Students can do well regardless of experience But you may have to work hard! If no experience, budget 10 hours of homework a week A B C D/F All Students 33% 45% 20% 2% AP Students 50% 40% 10% 0% Some Experience 45% 35% 20% 0% No Experience 25% 50% 22% 3% 8/23/16 Overview, Types & Expressions 17

Getting Started with Python Designed to be used from the command line OS X/Linux: Terminal Windows: Command Prompt Purpose of the first lab Once installed type python Starts an interactive shell Type commands at >>> Shell responds to commands Can use it like a calculator Use to evaluate expressions This class uses Python 2.7.x Python 3 has many issues May be incompatible 8/23/16 Overview, Types & Expressions 18

The Basics Values 42 12.345 integer float (real number) Types Hello! string (of characters) Expressions 34 * (23 + 14) 1.0 / 3.0 "Hel" + "lo!" 8/23/16 Overview, Types & Expressions 19

Python and Expressions An expression represents something Python evaluates it (turns it into a value) Similar to what a calculator does Examples: 2.3 Literal (evaluates to self) (3 * 7 + 2) * 0.1 An expression with four literals and some operators 8/23/16 Overview, Types & Expressions 20

Representing Values Everything on a computer reduces to numbers Letters represented by numbers (ASCII codes) Pixel colors are three numbers (red, blue, green) So how can Python tell all these numbers apart? Memorize this definition! Type: A set of values and the operations on them. Examples of operations: +, -, /, * The meaning of these depends on the type 8/23/16 Overview, Types & Expressions 21

Example: Type int Type int represents integers values:, 3, 2, 1, 0, 1, 2, 3, 4, 5, Integer literals look like this: 1, 45, 43028030 (no commas or periods) operations: +,, *, /, **, unary multiply to power of Principle: operations on int values must yield an int Example: 1 / 2 rounds result down to 0 Companion operation: % (remainder) 7 % 3 evaluates to 1, remainder when dividing 7 by 3 Operator / is not an int operation in Python 3 (use // instead) 8/23/16 Overview, Types & Expressions 22

Example: Type float Type float (floating point) represents real numbers 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 8/23/16 of float literal Overview, Types & Expressions 23

Floats Have Finite Precision 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 >>> 8/23/16 Overview, Types & Expressions 24

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! 8/23/16 Overview, Types & Expressions 25

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 8/23/16 Overview, Types & Expressions 26

Converting Values Between Types Basic form: type(value) float(2) converts value 2 to type float (value now 2.0) int(2.6) converts value 2.6 to type int (value now 2) Explicit conversion is also called casting Narrow to wide: bool int float Widening. Python does automatically if needed Example: 1/2.0 evaluates to 0.5 (casts 1 to float) Narrowing. Python never does this automatically Narrowing conversions cause information to be lost Example: float(int(2.6)) evaluates to 2.0 8/23/16 Overview, Types & Expressions 27