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

Similar documents
CS1 Lecture 3 Jan. 18, 2019

Algorithms and Programming I. Lecture#12 Spring 2015

ENGR 101 Engineering Design Workshop

CS1 Lecture 3 Jan. 22, 2018

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

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

Getting Started with Python

CMSC 201 Computer Science I for Majors

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

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

Midterms Save the Dates!

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

Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

Fundamentals of Programming (Python) Getting Started with Programming

Chapter 2 Working with Data Types and Operators

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

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

VARIABLES & ASSIGNMENTS

Python 2 Conditionals and loops Matthew Egbert CS111

Programming for Engineers in Python. Recitation 1

Lecture 1. Types, Expressions, & Variables

Topic 2: Introduction to Programming

Objectives. Structure. Munster Programming Training

Fundamentals of Programming. Lecture 1: Introduction + Basic Building Blocks of Programming

CSC 120 Computer Science for the Sciences. Week 1 Lecture 2. UofT St. George January 11, 2016

CSc 110, Spring 2017 Lecture 3: Expressions, Variables and Loops. Adapted from slides by Marty Stepp and Stuart Reges

SAMS Programming - Section C. Lecture 1: Introduction + Basic Building Blocks of Programming

CSI Lab 02. Tuesday, January 21st

Programming for Engineers in Python. Autumn

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

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

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

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

Full file at C How to Program, 6/e Multiple Choice Test Bank

Python Games. Session 1 By Declan Fox

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

DM550 Introduction to Programming part 2. Jan Baumbach.

CSC108: Introduction to Computer Programming. Lecture 1

IT 374 C# and Applications/ IT695 C# Data Structures

CIS 110: Introduction to Computer Programming

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

Python Unit

Chapter 2 Basic Elements of C++

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

CSE 115. Introduction to Computer Science I

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

Python 2 Conditionals and loops

Lecture 2: Python Arithmetic

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

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

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

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

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions.

Lecture 1. Course Overview Types & Expressions

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Lecture 2: Variables & Assignments

Extended Introduction to Computer Science CS1001.py Lecture 10, part A: Interim Summary; Testing; Coding Style

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

introduction (week 1)

CS 135 Lab Assignments Week 1

CMSC201 Computer Science I for Majors

CS1 Lecture 5 Jan. 26, 2018

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

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

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

COMP 202 Java in one week

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

Datatypes, Variables, and Operations

CS 112: Intro to Comp Prog

Full file at

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

CSCI Wednesdays: 1:25-2:15 Keller Thursdays: 4:00-4:50 Akerman 211

CS1 Lecture 5 Jan. 25, 2019

Lecture 5. Defining Functions

COMP 202 Java in one week

Introduction to: Computers & Programming Defining Identifiers: Objects with Names

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

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

PYTHON- AN INNOVATION

Act like a code monkey Coding Basics

Getting Started Values, Expressions, and Statements CS GMU

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

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

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Introduction to Software Development (ISD) David Weston and Igor Razgon

Visual C# Instructor s Manual Table of Contents

Expressions and Variables

Fundamentals of Programming CS-110. Lecture 3

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

CIS192: Python Programming

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

CS 1301 Exam 1 Answers Fall 2009

CME 193: Introduction to Scientific Python Lecture 1: Introduction

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

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

if Statement Numeric Rela5onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

Transcription:

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

Outline for Today Overview of Course A Python intro to be continued in lab on Wednesday (group A) and Thursday (group B) 7/3/2017 SAMS - Lecture 1 2

The Course Staff Me Mark Stehlik <mjs@cs.cmu.edu> Teaching Professor available 11:30 noon and 5:00 5:30 (GHC 6205) "The other guy" Anil Ada <aada@cs.cmu.edu>, teaching group C TAs 6 undergrads, available 6:30-9:00 and on weekends 7/3/2017 SAMS - Lecture 1 3

Course Logistics Course website: http://www.cs.cmu.edu/~aada/courses/sams17/ Lectures Come on time; use of electronic devices is prohibited during lecture (you re here to learn to program, not surf the web or talk to your friends do that on your time) Handin via autolab (more on this later) 7/3/2017 SAMS - Lecture 1 4

You Students who want to learn about programming and computer science No experience necessary (we will instrument that), not probably intending to major in CS (but ) 7/3/2017 SAMS - Lecture 1 5

Course content An Introduction to Computing (two parts): - understanding algorithms - implementing algorithms (writing programs); requires learning about, and practicing with, the tools : functions expressions conditionals loops strings lists graphics 7/3/2017 SAMS - Lecture 1 6

Course elements Homeworks due Saturday 5:00pm (this week there will be a short assignment due Thursday to make sure you can use the labs) Weekly quizzes on Friday 7/3/2017 SAMS - Lecture 1 7

Collaboration Policy There are no group assignments in this class Everyone should read and abide by: http://www.cmu.edu/policies/documents/academicintegrity.htm Here is some additional information for this course: You are allowed to talk with/work with other students on homework assignments You can share ideas You can discuss things at a high (algorithmic, non-code) level (pictures) You should not share (or even look at) code! You must turn in your own work Your solution should be different than others The harder the assignment, the more differences we should see You should NEVER copy another student s file as a basis for your solution. You should not let your files be copied by others! If you need help debugging, who do you ask? 7/3/2017 SAMS - Lecture 1 8

Programming vs. Computer Science 7/3/2017 SAMS - Lecture 1 9

What is Python? Python is a programming language What's a programming language? A language that has a set of instructions/statements that, when assembled correctly (syntactically and semantically) can be compiled/interpreted by a computer and run (executed) to perform a task So, it's a language, like English, Spanish, etc. with rules for syntax (creating grammatically correct statements) that have meaning (semantics) More on this as we go 7/3/2017 SAMS - Lecture 1 10

Arithmetic Expressions Mathematical Operators + Addition - Subtraction // Integer division * Multiplication ** Exponentiation / Division % Modulo (remainder) Python is like a calculator: type an expression and it tells you the value. >>> 2 + 3 * 5 17 7/3/2017 SAMS - Lecture 1 11

Order of Evaluation Use parentheses to force alternate precedence 7+ 5 * 6 (7 + 5) * 6 Operators that have the same precedence are applied left to right except for exponentiation. Exponentiation is applied right to left. 5 * 10 % 4 = (5 * 10) % 4 2 + 3 + 4 = (2 + 3) + 4 2 ** 3 ** 4 = 2 **(3 ** 4) 7/3/2017 SAMS - Lecture 1 12

Data Types Integers 4 15110-53 0 Floating Point Numbers 4.0-0.8 03333333333333333 7.34e+014 Strings "hello" "A" " " "" "7up!" 'there' '"' '15110' Booleans True False 7/3/2017 SAMS - Lecture 1 13

Integer division In Python3: 7 / 2 equals 3.5 7 // 2 equals 3 7 // 2.0 equals 3.0 7.0 // 2 equals 3.0-7 // 2 equals -4 beware! // rounds down to smaller number, not towards 0! 7/3/2017 SAMS - Lecture 1 14

Expressions vs. Statements Python evaluates an expression to get a value (number or other value) Python executes a statement to perform an action that has an effect (e.g., binding a value to a variable, printing something) 7/3/2017 SAMS - Lecture 1 15

Variables A variable is not an unknown as in algebra. In Python programming, a variable is a name you give a value. In Python we give a name to a value using an assignment statement: Assignment statement Expression Python s response >>> a = 5 >>> a 5 7/3/2017 SAMS - Lecture 1 a Computer memory 5 16

Variables All variable names must start with a letter (lowercase recommended). The remainder of the variable name (if any) can consist of any combination of uppercase letters, lowercase letters, digits and underscores (_). Identifiers in Python are case sensitive. Example: Value is different from value. 7/3/2017 SAMS - Lecture 1 17

Assignment statements In general variable_name = expression What happens? The expression on the right of the = is evaluated The variable on the left is bound to that value Examples a = 5 (a is assigned 5) a = 2 + 5 7/3/2017 SAMS - Lecture 1 18

Basic output Print print("hello") print("mark") Print multiple items print("hello", "Mark") print() # prints a blank line Print on same line print("hello", end ="") print("mark") 7/3/2017 SAMS - Lecture 1 19

Basic input Input a string name = input("enter your name: ") print("your name is:", name) Input an integer x = input("enter a number: ") print(x, "divided by 2 =", x/2) #Error! Input an integer correctly with int() x = int(input("enter a number: ")) print(x, "divided by 2 =", x/2) #prints as expected 7/3/2017 SAMS - Lecture 1 20

Built-in functions Math library A predefined module of mathematical values and functions we can use without writing the implementation Examples import math r = 5 + math.sqrt(2) radians = degrees * (math.pi/180) print(math.factorial(10)) 7/3/2017 SAMS - Lecture 1 21

Write your own function def function_name(parameter_list): statements def is a reserved word and cannot be used as a variable name. Indentation is critical. Use spaces only, not tabs!!!! 7/3/2017 SAMS - Lecture 1 22

Write your own function (example): def tip(total): return total * 0.18 >>> tip(100) 18.0 >>> tip(135.72) 24.4296 7/3/2017 SAMS - Lecture 1 23

Running Python In the shell (at the command line) In an IDE (Integrated Development Environment) like IDLE or Pyzo 7/3/2017 SAMS - Lecture 1 24

Program Errors Syntax ("compile-time") Python cannot understand what you have typed Runtime program crashes Logical/Semantic program runs but is incorrect 7/3/2017 SAMS - Lecture 1 25