L435/L555. Dept. of Linguistics, Indiana University Fall 2016

Similar documents
Functions in Python L435/L555. Dept. of Linguistics, Indiana University Fall Functions in Python. Functions.

Mathematical Logic Part Three

Math 144 Summer 2012 (UCR) Pro-Notes June 24, / 15

Topic 1: Propositional logic

CSE 105 THEORY OF COMPUTATION

8.2 Examples of Classes

Propositional Logic: Semantics and an Example

Discrete Mathematics and Its Applications

Introduction to Cryptology Dr. Sugata Gangopadhyay Department of Computer Science and Engineering Indian Institute of Technology, Roorkee

Mathematical Logic Part Three

Discrete Mathematics and Its Applications

7. Propositional Logic. Wolfram Burgard and Bernhard Nebel

COMP 204. Exceptions continued. Yue Li based on material from Mathieu Blanchette, Carlos Oliver Gonzalez and Christopher Cameron

CSCI 5582 Artificial Intelligence. Today 9/28. Knowledge Representation. Lecture 9

CS589 Principles of DB Systems Fall 2008 Lecture 4e: Logic (Model-theoretic view of a DB) Lois Delcambre

Logic: Bottom-up & Top-down proof procedures

Introduction to Python

Section 2.3: Statements Containing Multiple Quantifiers

CS177 Spring Final exam. Fri 05/08 7:00p - 9:00p. There are 40 multiple choice questions. Each one is worth 2.5 points.

Python & Numpy A tutorial

CS 220: Discrete Structures and their Applications. Propositional Logic Sections in zybooks

Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3

Using web-based Java pplane applet to graph solutions of systems of differential equations

Position and Displacement

CS177 Fall Midterm 1. Wed 10/07 6:30p - 7:30p. There are 25 multiple choice questions. Each one is worth 4 points.

Introduction to Python

Introduction to Proofs

Direct Proof and Proof by Contrapositive

Logic Background (1A) Young W. Lim 12/14/15

MCS 260 Exam 2 13 November In order to get full credit, you need to show your work.

Contradiction MATH Contradiction. Benjamin V.C. Collins, James A. Swenson MATH 2730

Problem Decomposition: One Professor s Approach to Coding

Assignment 4: Object creation

Propositional Language - Semantics

Read this before starting!

Extensions to the Logic of All x are y: Verbs, Relative Clauses, and Only

Theory of Computation

4.4 The Calendar program

Mathematical Preliminaries. Sipser pages 1-28

ICS141: Discrete Mathematics for Computer Science I

WARM-UP. Conditional Statements

UNIVERSITY OF VICTORIA DECEMBER EXAMINATIONS MATH 122: Logic and Foundations

Propositional Logic and Semantics

Mathematical Logic Part One

Natural deduction for truth-functional logic

Foundations of Artificial Intelligence

Foundations of Artificial Intelligence

/home/thierry/columbia/msongsdb/pyreport_tutorials/tutorial1/tutorial1.py January 23, 20111

Turing Machines Part Three

Agenda. Artificial Intelligence. Reasoning in the Wumpus World. The Wumpus World

Logic for Computer Science - Week 4 Natural Deduction

Mathematical Logic Part One

Syllogistic Logic and its Extensions

Contingency Tables. Safety equipment in use Fatal Non-fatal Total. None 1, , ,128 Seat belt , ,878

Structural Induction

- 1.2 Implication P. Danziger. Implication

TEACHER NOTES MATH NSPIRED

CPSC 121 Midterm 1 Tuesday, October 11th, 2011

Conceptual Explanations: Simultaneous Equations Distance, rate, and time

Logic. Propositional Logic: Syntax. Wffs

LECSS Physics 11 Introduction to Physics and Math Methods 1 Revised 8 September 2013 Don Bloomfield

TDDD08 Tutorial 1. Who? From? When? 6 september Victor Lagerkvist (& Wªodek Drabent)

1. Prove that the number cannot be represented as a 2 +3b 2 for any integers a and b. (Hint: Consider the remainder mod 3).

CSE 20: Discrete Mathematics

HOW TO WRITE PROOFS. Dr. Min Ru, University of Houston

8. Reductio ad absurdum

Examples. Example (1) Example (2) Let x, y be two variables, and denote statements p : x = 0 and q : y = 1. Solve. x 2 + (y 1) 2 = 0.

Propositional Logic. Fall () Propositional Logic Fall / 30

Testing a Hash Function using Probability

1 Newton s 2nd and 3rd Laws

Propositions. c D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 5.1, Page 1

Math 300 Introduction to Mathematical Reasoning Autumn 2017 Inverse Functions

Propositional Logic. Testing, Quality Assurance, and Maintenance Winter Prof. Arie Gurfinkel

Definition 2. Conjunction of p and q

Mathematical Notation

A High Level Programming Language for Quantum Computing

THE LOGIC OF COMPOUND STATEMENTS

Sequential Logic (3.1 and is a long difficult section you really should read!)

PHIL12A Section answers, 16 February 2011

Quantifiers. P. Danziger

Exercise 2. Prove that [ 1, 1] is the set of all the limit points of ( 1, 1] = {x R : 1 <

Python. chrysn

Final Exam Theory Quiz Answer Page

Introduction to Estimation Theory

Finite Math Section 6_1 Solutions and Hints

3 The Semantics of the Propositional Calculus

Truth-Functional Logic

Advanced Topics in LP and FP

Introduction to Python for Biologists

Recitation Week 3. Taylor Spangler. January 23, 2012

Modal Logics. Most applications of modal logic require a refined version of basic modal logic.

CSE 140 Lecture 11 Standard Combinational Modules. CK Cheng and Diba Mirza CSE Dept. UC San Diego

CS177 Spring Midterm 2. April 02, 8pm-9pm. There are 25 multiple choice questions. Each one is worth 4 points.

CS 331: Artificial Intelligence Propositional Logic I. Knowledge-based Agents

Knowledge-based Agents. CS 331: Artificial Intelligence Propositional Logic I. Knowledge-based Agents. Outline. Knowledge-based Agents

Section 1.1: Logical Form and Logical Equivalence

Undecidability and Rice s Theorem. Lecture 26, December 3 CS 374, Fall 2015

1 Opening URLs. 2 Regular Expressions. 3 Look Back. 4 Graph Theory. 5 Crawler / Spider

1.2 The Role of Variables

Systems of Linear Equations and Inequalities

Transcription:

in in L435/L555 Dept. of Linguistics, Indiana University Fall 2016 1 / 13

in we know how to output something on the screen: print( Hello world. ) input: input(<prompt>) returns the input from the keyboard Example name = input ( type your name : ) 2 / 13

If statement in Write a program to: 1) ask a user to type his/her name, 2) check the user is known, & 3) print a welcome statement we know how to do the first part: known users = [ Sandra, Markus ] name = input ( type your name : ) We can check whether a person is in the list of known users: name in known users But how do we tell python to print a welcome message the name is known? 3 / 13

If statement in syntax: i f <t e s t >: do t h i s full program: known users = [ Sandra, Markus ] name = input ( type your name : ) i f name i n known users : p r i n t ( Hello + name) http: //www.greenteapress.com/thinkpython/html/thinkpython006.html 4 / 13

in Definition In python, blocks are created by the use of a colon, followed by an indented section of text. i f <t e s t >: do something do another t h i n g a f i n a l t h i n g do t h i s regardless 5 / 13

Truth values in a test (in the statement) corresponds to a yes/no question and can be either true or false the following values count as false: False None 0 [] (empty list) {} (empty dict) (empty string) () (empty tuple) everything else counts as true! 6 / 13

statements in In case the program needs to do something when the test is false, use the else statement E.g. a user is not known, add him/her to the list Example known users = [ Sandra, Markus ] name = input ( type your name : ) i f name i n known users : p r i n t ( Hello + name +. ) p r i n t ( I t i s nice to have you back. ) else : known users. append (name) p r i n t ( You have been added to the l i s t. ) 7 / 13

El in you want to check the next condition in the else case, there is a shortcut for else called el Example known users = [ Sandra, Markus ] name = input ( type your name : ) i f name i n known users : p r i n t ( Hello + name +. ) p r i n t ( I t i s nice to have you back. ) e l i f len (name) > 20: p r i n t ( Your name i s too long! ) else : known users. append (name) p r i n t ( You have been added to the l i s t. ) 8 / 13

in Example known users = [ Sandra, Markus ] name = input ( type your name : ) i f name i n known users : p r i n t ( Hello + name +. ) i f name. s t a r t s w i t h ( Dr. ) : p r i n t ( Taking y o u r s e l f s e r i o u s l y, huh? ) else : p r i n t ( You \ re my buddy. ) else : known users. append (name) p r i n t ( You have been added to the l i s t. ) 9 / 13

in x == y x < y x > y x >= y x <= y x!= y x is y x is not y x in y x not in y x equals y x is less than y x is greater than y x is greater than or equal to y x is less than or equal to y x is not equal to y x is the same object as y x is not the same object as y x is a member of y x is not a member of y Caution: = and == are dferent: = assigns a value == compares values 10 / 13

Equality vs. identity in Having the same values is not the same thing as being the same object >>> x = y = [ 1, 2, 3] >>> z = [ 1, 2, 3] >>> x == y True >>> x == z True >>> x is y True >>> x is z False 11 / 13

in Definition You can combine conditions with and and or, and negate with not Example i f 5 < x < 10 and x not in y : p r i n t ( x i s between 5 and 10 ) p r i n t ( and i s not i n the l i s t y ) 12 / 13

Short-circuit logic in evaluates the first part of an and/or condition and can short circuit If x in x or y is True, no need to evaluate both If x in x and y is False, no need to evaluate both This means you can do things like: line and line.startswith( % ): You can also do things like: name = input( Please enter your name: ) or <unknown> 13 / 13