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

Similar documents
MITOCW watch?v=ytpjdnlu9ug

Start to Code. Instructor: Xiao Liu

Introduction in. Programming 1. programming. Course 1

Monty Python and the Holy Grail (1975) BBM 101. Introduction to Programming I. Lecture #03 Introduction to Python and Programming, Control Flow

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

DECOMPOSITION, ABSTRACTION, FUNCTIONS

COURSE OF STUDY UNIT PLANNING GUIDE COMPUTER SCIENCE 1 FOR: 5 CREDITS GRADE LEVEL: 9-12 FULL-YEAR COURSE PREPARED BY: SUSIE EISEN

BASIC ELEMENTS OF A COMPUTER PROGRAM

Full file at

CS111: PROGRAMMING LANGUAGE II

cs1114 REVIEW of details test closed laptop period

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

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

Project 1. due date Sunday July 8, 2018, 12:00 noon

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

Introduction to Python and Programming. 1. Python is Like a Calculator. You Type Expressions. Python Computes Their Values /2 2**3 3*4+5*6

Lecture 1. Course Overview, Python Basics

Basic Scheme February 8, Compound expressions Rules of evaluation Creating procedures by capturing common patterns

Fundamentals of Programming (Python) Getting Started with Programming

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CMSC 201 Computer Science I for Majors

Lecture 1. Course Overview, Python Basics

Visual Basic for Applications

Welcome to CS 115 (Winter 2019)

You must pass the final exam to pass the course.

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

Chapter 2 Basic Elements of C++

Pace University. Fundamental Concepts of CS121 1

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Full file at

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

6.001 Notes: Section 6.1

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Introduction to Computation for the Humanities and Social Sciences. CS 3 Chris Tanner

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

CS558 Programming Languages

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Welcome to CS 115 (Winter 2018)

Algorithms and Programming I. Lecture#12 Spring 2015

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

Lecture 1. Types, Expressions, & Variables

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

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

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

Lecture 2: Variables & Assignments

1/11/2010 Topic 2: Introduction to Programming 1 1

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Text Input and Conditionals

PROGRAMMING FUNDAMENTALS

Objectives. In this chapter, you will:

COMP 102: Computers and Computing

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

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

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

Lecture 9: Lists. MIT-AITI Kenya 2005

Values, Variables, Types & Arithmetic Expressions. Agenda

6.096 Introduction to C++

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Topic 2: Introduction to Programming

CIS 110: Introduction to Computer Programming

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Programming for Engineers in Python. Autumn

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

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

TESTING, DEBUGGING, EXCEPTIONS, ASSERTIONS

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

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

Principles of Programming Languages

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Java Outline (Upto Exam 2)

Announcements. 1. Forms to return today after class:

Chapter 2: Basic Elements of C++

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

PIC 10A. Review for Midterm I

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Programming for Engineers in Python. Recitation 1

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Lesson 3: Basic Programming Concepts

Class Structure. Prerequisites

Java Fall 2018 Margaret Reid-Miller

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

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

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Ex: If you use a program to record sales, you will want to remember data:

Computer Components. Software{ User Programs. Operating System. Hardware

Programming with Java

6.033 Spring Lecture #6. Monolithic kernels vs. Microkernels Virtual Machines spring 2018 Katrina LaCurts

Recall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean?

CS61A Lecture 1. Amir Kamil UC Berkeley January 23, 2013

SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

Control Structures: The IF statement!

Program Verification & Testing; Review of Propositional Logic

CSE 115. Introduction to Computer Science I

Chapter 1: Building Blocks of Programming

Welcome to CS 135 (Winter 2018)

Fundamentals: Expressions and Assignment

6.001 Notes: Section 1.1

Chapter 2 C++ Fundamentals

Problem Solving for Intro to Computer Science

Transcription:

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

TODAY course info what is computation python basics mathematical operations python variables and types NOTE: slides and code files up before each lecture o highly encourage you to download them before lecture o take notes and run code files when I do o bring computers to answer in-class practice exercises! 6.0001 LECTURE 1 2

COURSE INFO Grading approx. 20% Quiz approx. 40% Final approx. 30% Problem Sets approx. 10% MITx Finger Exercises 6.0001 LECTURE 1 3

COURSE POLICIES Collaboration may collaborate with anyone required to write code independently and write names of all collaborators on submission we will be running a code similarity program on all psets Extensions no extensions late days, see course website for details drop and roll weight of max two psets in final exam grade should be EMERGENCY use only 6.0001 LECTURE 1 4

RECITATIONS not mandatory two flavors 1) Lecture review: review lecture material o o if you missed lecture if you need a different take on the same concepts 2) Problem solving: teach you how to solve programming problems o o o o o useful if you don t know how to set up pseudocode from pset words we show a couple of harder questions walk you through how to approach solving the problem brainstorm code solution along with the recitation instructor will post solutions after 6.0001 LECTURE 1 5

FAST PACED COURSE Position yourself to succeed! read psets when they come out and come back to them later use late days in emergency situations New to programming? PRACTICE. PRACTICE? PRACTICE! can t passively absorb programming as a skill download code before lecture and follow along do MITx finger exercises don t be afraid to try out Python commands! 6.0001 LECTURE 1 6

PROBLEM SOLVING PRACTICE KNOWLEDGE OF CONCEPTS PROGRAMMING SKILL 6.0001 LECTURE 1 7

TOPICS represent knowledge with data structures iteration and recursion as computational metaphors abstraction of procedures and data types organize and modularize systems using object classes and methods different classes of algorithms, searching and sorting complexity of algorithms 6.0001 LECTURE 1 8

WHAT DOES A COMPUTER DO Fundamentally: performs calculations a billion calculations per second! remembers results 100s of gigabytes of storage! What kinds of calculations? built-in to the language ones that you define as the programmer computers only know what you tell them 6.0001 LECTURE 1 9

TYPES OF KNOWLEDGE declarative knowledge is statements of fact. someone will win a Google Cardboard before class ends imperative knowledge is a recipe or how-to. 1) Students sign up for raffle 2) Ana opens her IDE 3) Ana chooses a random number between 1 st and n th responder 4) Ana finds the number in the responders sheet. Winner! 6.0001 LECTURE 1 10

A NUMERICAL EXAMPLE square root of a number x is y such that y*y = x recipe for deducing square root of a number x (16) 1) Start with a guess, g 2) If g*g is close enough to x, stop and say g is the answer 3) Otherwise make a new guess by averaging g and x/g 4) Using the new guess, repeat process until close enough g g*g x/g (g+x/g)/2 3 9 16/3 4.17 4.17 17.36 3.837 4.0035 4.0035 16.0277 3.997 4.000002 6.0001 LECTURE 1 11

WHAT IS A RECIPE 1) sequence of simple steps 2) flow of control process that specifies when each step is executed 3) a means of determining when to stop 1+2+3 = an algorithm! 6.0001 LECTURE 1 12

COMPUTERS ARE MACHINES how to capture a recipe in a mechanical process fixed program computer calculator stored program computer machine stores and executes instructions 6.0001 LECTURE 1 13

BASIC MACHINE ARCHITECTURE MEMORY CONTROL UNIT program counter ARITHMETIC LOGIC UNIT do primitive ops INPUT OUTPUT 6.0001 LECTURE 1 14

STORED PROGRAM COMPUTER sequence of instructions stored inside computer built from predefined set of primitive instructions 1) arithmetic and logic 2) simple tests 3) moving data special program (interpreter) executes each instruction in order use tests to change flow of control through sequence stop when done 6.0001 LECTURE 1 15

BASIC PRIMITIVES Turing showed that you can compute anything using 6 primitives modern programming languages have more convenient set of primitives can abstract methods to create new primitives anything computable in one language is computable in any other programming language 6.0001 LECTURE 1 16

CREATING RECIPES a programming language provides a set of primitive operations expressions are complex but legal combinations of primitives in a programming language expressions and computations have values and meanings in a programming language 6.0001 LECTURE 1 17

ASPECTS OF LANGUAGES primitive constructs English: words programming language: numbers, strings, simple operators Word Cloud copyright Michael Twardos, All Right Reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use/. Word Cloud copyright unknown, All Right Reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use/. 6.0001 LECTURE 1 18

ASPECTS OF LANGUAGES syntax English: "cat dog boy" not syntactically valid "cat hugs boy" syntactically valid programming language: "hi"5 not syntactically valid 3.2*5 syntactically valid 6.0001 LECTURE 1 19

ASPECTS OF LANGUAGES static semantics is which syntactically valid strings have meaning English: "I are hungry" syntactically valid but static semantic error programming language: 3.2*5 syntactically valid 3+"hi" static semantic error 6.0001 LECTURE 1 20

ASPECTS OF LANGUAGES semantics is the meaning associated with a syntactically correct string of symbols with no static semantic errors English: can have many meanings "Flying planes can be dangerous" programming languages: have only one meaning but may not be what programmer intended 6.0001 LECTURE 1 21

WHERE THINGS GO WRONG syntactic errors common and easily caught static semantic errors some languages check for these before running program can cause unpredictable behavior no semantic errors but different meaning than what programmer intended program crashes, stops running program runs forever program gives an answer but different than expected 6.0001 LECTURE 1 22

PYTHON PROGRAMS a program is a sequence of definitions and commands definitions evaluated commands executed by Python interpreter in a shell commands (statements) instruct interpreter to do something can be typed directly in a shell or stored in a file that is read into the shell and evaluated Problem Set 0 will introduce you to these in Anaconda 6.0001 LECTURE 1 23

OBJECTS programs manipulate data objects objects have a type that defines the kinds of things programs can do to them Ana is a human so she can walk, speak English, etc. Chewbacca is a wookie so he can walk, mwaaarhrhh, etc. objects are scalar (cannot be subdivided) non-scalar (have internal structure that can be accessed) 6.0001 LECTURE 1 24

SCALAR OBJECTS int represent integers, ex. 5 float represent real numbers, ex. 3.27 bool represent Boolean values True and False NoneType special and has one value, None can use type() to see the type of an object >>> type(5) int >>> type(3.0) float 6.0001 LECTURE 1 25

TYPE CONVERSIONS (CAST) can convert object of one type to another float(3) converts integer 3 to float 3.0 int(3.9) truncates float 3.9 to integer 3 6.0001 LECTURE 1 26

PRINTING TO CONSOLE to show output from code to a user, use print command In [11]: 3+2 Out[11]: 5 In [12]: print(3+2) 5 6.0001 LECTURE 1 27

EXPRESSIONS combine objects and operators to form expressions an expression has a value, which has a type syntax for a simple expression <object> <operator> <object> 6.0001 LECTURE 1 28

OPERATORS ON ints and floats i+j i-j i*j i/j the sum the difference the product division if both are ints, result is int if either or both are floats, result is float result is float i%j the remainder when i is divided by j i**j i to the power of j 6.0001 LECTURE 1 29

SIMPLE OPERATIONS parentheses used to tell Python to do these operations first operator precedence without parentheses ** * / + and executed left to right, as appear in expression 6.0001 LECTURE 1 30

BINDING VARIABLES AND VALUES equal sign is an assignment of a value to a variable name pi = 3.14159 pi_approx = 22/7 value stored in computer memory an assignment binds name to value retrieve value associated with name or variable by invoking the name, by typing pi 6.0001 LECTURE 1 31

ABSTRACTING EXPRESSIONS why give names to values of expressions? to reuse names instead of values easier to change code later pi = 3.14159 radius = 2.2 area = pi*(radius**2) 6.0001 LECTURE 1 32

PROGRAMMING vs MATH in programming, you do not solve for x pi = 3.14159 radius = 2.2 # area of circle area = pi*(radius**2) radius = radius+1 6.0001 LECTURE 1 33

CHANGING BINDINGS can re-bind variable names using new assignment statements previous value may still stored in memory but lost the handle for it value for area does not change until you tell the computer to do the calculation again pi = 3.14 radius = 2.2 area = pi*(radius**2) radius = radius+1 pi radius area 3.14 2.2 3.2 15.1976 6.0001 LECTURE 1 34

MIT OpenCourseWare https://ocw.mit.edu 6.0001 Introduction to Computer Science and Programming in Python Fall 2016 For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.