1 / 21

Logical Thinking

Logical Thinking. CS 104 9/12/11. Agenda. Today College Board survey reminder Note: Simple “how to” guide on Scratch posted on eLearning Review HW #2 Review of control constructs Examples in BYOB Scratch Wednesday Quiz #2 on Wednesday Review Research Paper #1 More BYOB Scratch ideas.

ogden
Télécharger la présentation

Logical Thinking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Logical Thinking CS 104 9/12/11

  2. Agenda • Today • College Board survey reminder • Note: Simple “how to” guide on Scratch posted on eLearning • Review HW #2 • Review of control constructs • Examples in BYOB Scratch • Wednesday • Quiz #2 on Wednesday • Review Research Paper #1 • More BYOB Scratch ideas

  3. Review: Decision Structure • “if” statements are used to test whether a certain condition is met • This requires comparison operators and a way to connect multiple comparisons to create complex statements

  4. Comparison Operators • Relational Operators: Evaluate to true or false • Scratch does not provide <>, >= or <= • These can be simulated as • x > 10 or x = 10, and not x = 10

  5. Operator Precedence • What is 2 + 3 * 4? • What about (2 + 3) * 4? • The concept of operator precedence dictates which operators are applied first and have higher importance • In most programming languages, the order is: • terms inside parentheses or brackets • exponents and roots • multiplication and division As they appear left to right • addition and subtraction As they appear left to right

  6. Comparison Operators:You Answer TRUE 5 < 7 FALSE 3>9 FALSE 5 <= 4 TRUE 5 > 4

  7. Comparison Operators:You Answer (5 + 2) < 7 FALSE FALSE 3> (9 / 3) (5 * 4) >= (4 * 5) TRUE FALSE (5 / 2) > 4

  8. Boolean Operators • Boolean logic – basis of computer logic, used to create complex comparisons • Invented by George Boole, an English mathematician and philosopher ... no general method for the solution of questions in the theory of probabilities can be established which does not explicitly recognise ... those universal laws of thought which are the basis of all reasoning ... http://en.wikipedia.org/wiki/George_Boole

  9. Boolean Operators • AND • Both conditions must be true in order for the entire condition to be true • OR • At least one condition must be true in order for the entire condition to be true • NOT • Opposite; if the condition is true, the result is false, and if the condition is false, the result is true • Operator Precedence • Not • And • Or

  10. Boolean Operators: ANDYou Answer 5 < 7 AND 3 < (2 * 2) 5 < 7 true 3 < 4 true TRUE and true = true

  11. Boolean Operators: ORYou Answer 8 < 7 or 4 >= 4 8 < 7 false 4 >= 4 true false or true = true

  12. Boolean Operators: ComplexYou Answer (8 < 7 or 4 >= 4) AND (Not (1 > 9)) 8 < 7 false true 4 >= 4 false or true = true

  13. Boolean Operators: ComplexYou Answer True AND (Not (1 > 9)) 1 > 9 false Not false true True AND true true

  14. Truth Tables

  15. Truth Tables • Implication, we denote as => • "If it rains, I will stay at home"There are 4 possibilities:1) it rains and he stays at home      This is compatible with the statement: he did not lie.2) it rains and he does not stay at home      This is NOT compatible with the statement: he lied.3) it does not rain and he stays at home      This is compatible with the statement: he did not lie.4) it does not rain and he does not stay at home      This is compatible with the statement: he did not lie.

  16. Grader A B • Write a program to assign a letter grade to a given numeric grade. • If the given grade is between 90 and 100, print an A. • If the given grade is between 80 and 89, print a B. • If the given grade is between 70 and 79, print a C. • If the given grade is less than 70, print an F. F C

  17. Review: Loops • Loops are used to perform a single task repetitively until a specified condition is met

  18. Types of Loops • Infinite loops • The command(s) placed inside a never ending loop will repeat until the program is stopped • For loops • The loop will execute for a specified number of times

  19. Types of Loops • While loop • This loop will repeat while the specified condition is true • Do Until loop • This loop will repeat until the specified condition is true

  20. Class Grader A B • Write a program to average three grades per student. The grades will be submitted by the user, and the number of students in the class should be a random number. • If the average grade is between 90 and 100, print an A. • If the average grade is between 80 and 89, print a B. • If the average grade is between 70 and 79, print a C. • If the average grade is less than 70, print an F. F C

  21. Next Time • Quiz #2 9/14/11 • HW #2 due 9/21/11 • Feel free to email both Dr. Gray and Amber with any questions

More Related