Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computational Linguistics Programming I.

Similar presentations


Presentation on theme: "Introduction to Computational Linguistics Programming I."— Presentation transcript:

1 Introduction to Computational Linguistics Programming I

2 Resumé Algorithm: A well defined procedure for the solution of a given problem in a finite number of steps. Program: A set of instructions, written in a specific programming language, which a computer follows in solving a problem. Control Structures specify how instructions are followed

3 Examples of Control Structures Sequence: a series of instructions that are executed in order. Branch: an instruction involving a condition that affects the next instruction executed. Loop: for handling repeated execution. Module: a named collection of instructions that we write once but use in different contexts

4 Sequence

5 Branch

6 Loop

7 Module

8 Python Python is a programming language that allows us to write programs. Python programs have to obey certain syntactic conventions Python is also an interpreter, i.e. a machine which understands the conventions of the language

9 Python is also an Interpreter that Understands Python Programs PROGRAM WRITTEN IN PYTHON PYTHON INTERPRETER OUTPUT INPUT

10 Here is the World’s Simplest Python Program print “Hello World” When this program is run (interpreted) it causes “Hello World” to be printed on the screen.

11 Demo

12 The print statement The print statement consists of the word print followed by one or more arguments separated by commas: >>> print "a", "b", "c" abc In this case the arguments are strings.

13 Strings In Python strings are enclosed in either single quotes or double quotes. 'abc' "abc" "my name is" "Mike's name is"

14 Multi-line programs Here is a program consisting of a sequence of three instructions print "My name is " print "Mike" print "!"

15 Data Data is the raw material that programs manipulate. Data comes in different flavours called types Examples of data types are integer strings Each type of data is associated with characteristic operations.

16 Examples of operators Integers are associated with operators such as +, -, * etc. Using these operators we can write down complex expressions e.g. 2+2; 2-2; 2*2

17 Other Arithmetic Operators OperationSymbolExample Exponentiation **5 ** 2 == 25 Multiplication *2 * 3 == 6 Division /14 / 3 == 4 Remainder %14 % 3 == 2 Addition +1 + 2 == 3 Subtraction -4 - 3 == 1

18 Arithmetic expressions a number: 1 a variable: b an expression involving an operator a + 1 a complex expression a + 3*2 / 3 to eliminate ambiguity complex expressions can use parentheses (a + (3*2)) /3

19 Exercise 1.1 Discover the value of the following arithmetic expressions using the python interpreter 1 + 2/3 + 4 (1 + 2) / (3 + 4) 100 % 10 115 % 10

20 Multi-line program using arithmetic expressions print "2 + 2 is", 2+2 print "3 * 4 is", 3 * 4 print 100 - 1, " = 100 – 1" print "(33 + 2) / 5 + 11.5 = ",(33 + 2) / 5 + 11.5 What is the output of this program?

21 Python Editor Python allows us to edit, save, check and run programs. In python shell, go to File menu. Select New Editor window appears Type program into editor window. To check or run program – go to Run menu and select check or run. You will be prompted to save file. Any filename is OK, but filename.py is best.

22 Exercise 1.2 Use editor to write programs that print your name and date of birth on same line on separate lines print the numbers from 0 to 4 Save the work in different files Run the programs


Download ppt "Introduction to Computational Linguistics Programming I."

Similar presentations


Ads by Google