CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 3: Conditional Expressions.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
Logic Gates.
Logical Operators and While Loops CS303E: Elements of Computers and Programming.
PHYS707: Special Topics C++ Lectures Lecture 2. Summary of Today’s lecture: 1.More data types 2.Flow control (if-else, while, do-while, for) 3.Brief introduction.
Computer Science & Engineering 2111 IF and Boolean Functions 1 CSE 2111 Lecture-IF and Boolean Functions.
CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 4: Review Conditional & Word Stuff.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 18: HOF.
CSC 160 Computer Programming for Non-Majors Lecture #9: Booleans Prof. Adam M. Wittenstein
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 26: Printing and Stuff.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 14: Number Spelling Mini-project.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 12: Homework stuff and Accumulating Recursion.
Defining functions in lisp In lisp, all programming is in terms of functions A function is something which –takes some arguments as input –does some computing.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 19: HOF Problems.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 6: Mini-Project Prep.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 10: Recursion Rocks Again!
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 5: Decision Control Structures.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 13: Bugs and Two Stage Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 20: Tree Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 11: Accumulating Recursion.
SICP Interpretation part 1 Parts of an interpreter Arithmetic calculator Names Conditionals and if Store procedures in the environment.
Eight compound procedures and higher-order procedures.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 8: Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 9: Recursion Rocks!
CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB.
Midterm Logistics Where? 2050 VLSB When? Monday, 4:10 to 5:40 What to do? –“Review problems” from Thursday/Friday in UCWise. –Two practice exams and solutions.
CSC 160 Computer Programming for Non-Majors Chapter 4: Conditional Expressions and Functions Prof. Adam M. Wittenstein
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 2: Review – Writing Procedures.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 16: Let and Lambda.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 25: Trees and Generalized Lists.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 27: Review – most children and truth about cons.
Thirteen conditional expressions: letting programs make “decisions”
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 7: Review.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 5: Difference Between Dates Case Study.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 24: Review for lists, map and member.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Course Overview and Road Map Computability and Logic.
Computer Science – Truth Jam Table JamBreadSandwich Yes No YesNo YesNo TeaMilkDrink No Yes NoYes NoYes What am I getting at?
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 4: Chapter 4: Slide 1 Unit 4 Decisions Chapter 4 Making Decisions and Working.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
CS61A Lecture Colleen Lewis. Clicker poll Where do you think you’re learning the most? I assume you’ll learn the most in lab & disc (so.
DIGITAL ELECTRONICS. Everything in digital world is based on binary system. Numerically it involves only two symbols 0 or 1. –0 = False = No –1 = True.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
Introduction to Predicates and Quantified Statements I Lecture 9 Section 2.1 Wed, Jan 31, 2007.
Random Functions Selection Structure Comparison Operators Logical Operator
Logic Gates.
Chapter 4: Decision Structures and Boolean Logic
CSC115 Introduction to Computer Programming
CSC530 Data Structure - Decision
Types, Truth, and Expressions (Part 2)
Making Logical Decisions (IF-THEN-ELSE)
Chapter 4: Decision Structures and Boolean Logic
Logic Gates.
Introduction to Predicates and Quantified Statements I
Conditional Logic Presentation Name Course Name
Nate Brunelle Today: Conditional Decision Statements
Evaluating Boolean expressions
Chapter 4: Decision Structures and Boolean Logic
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Presentation transcript:

CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 3: Conditional Expressions

Today Questions about sentences and words Conditionals if booleans predicates cond and, or, and not

Coming up: conditionals Conditionals allow programs to do different things depending on data values To make decisions "Intelligence" depends on this it is hard to imagine any interesting program that doesn't do different things depending on what it is given

Structure of conditionals (if ;; test ;; action (if true) ) ;; action (if false) (define (mother-says temperature) (if (< temperature 90) ‘(you should wear a coat!) ‘(drink plenty of water!)) ) (mother-says 80) (mother-says 100)

true? or false? We need Booleans: something that represents truth or 'not truth' to the computer: #t, #f (odd? 3)  #t in practice, everything is true except #f (if 'joe '(hi joe) '(who are you))  (hi joe) false (the word with 5 letters) is true! (really, false is #t )

Predicates Predicates are procedures that return #t or #f by convention, their names end with a "?" odd? (odd? 3)  #t even? (even? 3)  #f vowel? (vowel? 'a)  #t (vowel? (first 'fred))  #f sentence? (sentence? 'fred)  #f

cond is helps organize lots of different options (cond (test-1 return-if-test1-true) (test-2 return-if-test2-true)... (else return-if-no-other-test-is-true) ))

and, or and not and takes any number of arguments, and returns true only if all are true or takes any number of arguments, and returns true if any are true not takes a single argument, and returns true only if the argument is false. (if (not (and #t #t #t #f)) 'yes 'awwwww)  yes