CSE 115. Introduction to Computer Science I

Similar documents
CSE 113 A. Announcements - Lab

CSE 115. Introduction to Computer Science I

Flow Control. So Far: Writing simple statements that get executed one after another.

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018

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

Conditionals & Control Flow

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CS100: CPADS. Decisions. David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania

Conditionals and Recursion. Python Part 4

EECS 183. Week 3 - Diana Gage. www-personal.umich.edu/ ~drgage

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

Selection Statement ( if )

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

C ONTROL AND H IGHER O RDER F UNCTIONS

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

Structure of Programming Languages Lecture 5

Flow Control: Branches and loops

Lecture 7. Memory in Python

61A Lecture 3. Friday, September 5

CS1 Lecture 3 Jan. 18, 2019

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

PREPARING FOR PRELIM 1

Announcements - Grades UBLearns grades just updated Monday, March 28 th (11:00am). Please check grades.

CSC 2500: Unix Lab Fall 2016

CS1 Lecture 3 Jan. 22, 2018

Test #2 October 8, 2015

Lecture 8. Conditionals & Control Flow

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

Write a code fragment that prints yes if xc is in the interval and no if it is not.

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

Comp 151. Control structures.

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators

Introduction to Programming

CONTROL AND ENVIRONMENTS 1

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

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

Lab 4 CSE 7, Spring 2018 This lab is an introduction to using logical and comparison operators in Matlab.

CONTROL AND HIGHER ORDER FUNCTIONS 1

61A Lecture 21. Friday, March 13

Control Flow: Branching booleans and selection statements CS GMU

Comp 151. Control structures.

ME30 Lab3 Decisions. February 20, 2019

CS18000: Problem Solving And Object-Oriented Programming

CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I. Dr. Carl Alphonce Dr. Jesse Hartloff

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE 131 Introduction to Computer Science Fall Exam I

CSE Section 10 - Dataflow and Single Static Assignment - Solutions

CSC 101: Lab #5 Boolean Logic Practice Due Date: 5:00pm, day after lab session

How Do Robots Find Their Way?

Conditionals: Making Choices

CSE 1223: Introduction to Computer Programming in Java Chapter 3 Branching

15-110: Principles of Computing, Spring 2018

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

CSE 115. Introduction to Computer Science I

Part III Appendices 165

CS111: PROGRAMMING LANGUAGE II

cs1114 REVIEW of details test closed laptop period

15-110: Principles of Computing, Spring 2018

HW3: CS 110X C Domain Information. Final Version: 1/29/2014

Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions. 1 Control. If statements. Boolean Operators

Introduction to Programming

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

Python, Part 2 CS 8: Introduction to Computer Science Lecture #4

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

CSI33 Data Structures

2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each.

Lab1. Introduction to Python. Lab 4: Selection Statement. Eng. Mai Z. Alyazji

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

CS 1301 CS1 with Robots Summer 2007 Exam 1

CSE 504: Compiler Design

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Invent Your Own Computer Games with Python

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CS 61A Control and Environments Spring 2018 Discussion 1: January 24, Control. If statements. Boolean Operators

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

Conditionals. C-START Python PD Workshop

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Lab 5 - Repetition. September 26, 2018

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

CS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures

AE Computer Programming for Aerospace Engineers

15-110: Principles of Computing, Spring 2018

The L Line. The Express Line to Learning. Wiley Publishing All Rights Reserved.

CIS 130 Exam #2 Review Suggestions

Conditional Expressions and Decision Statements

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CIS192 Python Programming. Robert Rand. August 27, 2015

More Coding Basics with Some Turtle

Accelerating Information Technology Innovation

ENGR 102 Engineering Lab I - Computation

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

CS 112: Intro to Comp Prog

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

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

Intensive Introduction to Computer Science. Course Overview Programming in Scratch

COMP 401 COURSE OVERVIEW

Python Activity 5: Boolean Expressions and Selection Statements

Transcription:

CSE 115 Introduction to Computer Science I

Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu

Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu autograder enforces deadlines strictly

Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK

Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK we will address submission issues / week 1 glitches

Announcements Lab exams You have 55 minutes to complete your work. The second half of the recitation is reserved for other tasks/activities.

Road map Review control flow (sequencing, selection, repetition) sequencing selection

Review relational expressions Boolean expressions

Relational operators https://docs.python.org/3.7/library/stdtypes.html#comparisons Operation Meaning < strictly less than <= less than or equal > strictly greater than >= greater than or equal == equal!= not equal

Boolean operators https://docs.python.org/3.7/library/stdtypes.html#boolean-operationsand-or-not Operation Result Notes x or y if x is false, then y, else x (1) x and y if x is false, then x, else y (2) not x if x is false, then True, else (3) Notes: 1.This is a short-circuit operator, so it only evaluates the second argument if the first one is false. 2.This is a short-circuit operator, so it only evaluates the second argument if the first one is true. 3.not has a lower priority than non-boolean operators, so not a == b is interpreted as not (a == b), and a == not b is a syntax error.

Boolean expressions examples True or a and b x < y and y <= z x < y <= z Convenient, but unusual across languages.

Road map Review control flow (sequencing, selection, repetition) sequencing selection

SEQUENCING SELECTION REPETITION

Sequencing Statements in a block are executed in sequence. (i.e. one after the other, in the order written) This is what we've seen so far.

Selection One of a set of instructions is executed, based on the outcome of a decision. Exactly one of many possible branches is followed.

Repetition A block is repeated several times, based on the outcome of a decision. Also called looping.

visualizing We use "flow charts" to help visualize the flow of control through a program, when appropriate. SIMPLE STATEMENT DECISION arrow depicts FLOW OF CONTROL

visualizing sequences a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a

visualizing sequences Control starts at the arrow whose origin is not connected to a box a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a

visualizing sequences a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a Control ends at the arrow whose terminus is not connected to a box

Selection: the if statement Here's an example of an if statement: if x < y :

Selection: the if statement 'if' is a keyword if x < y :

Selection: the if statement 'x < y' is a Boolean expression if x < y :

Selection: the if statement : is a delimiter if x < y :

Selection: the if statement What follows the ':' is a block (sequence) of statements. if x < y : Recall Python refers to the a block of statements as a "suite".

visualizing selection (if) if x < y : x < y True

visualizing selection (if) if x < y : x < y True

visualizing selection (if) if x < y : x < y True

visualizing selection (if) if x < y : x < y True

visualizing selection (if-else) if x < y : else : x < y True

visualizing selection (if-else) if x < y : else : x < y True

visualizing selection (if-else) if x < y : else : x < y True

visualizing selection (if-else) if x < y : else : x < y True

visualizing selection (if-else) if x < y : else : x < y True

visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0

visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0

visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0

visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0

visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0