Lilian Blot TO PROGRAMMING & PYTHON Introduction Autumn 2012 TPOP 1.

Slides:



Advertisements
Similar presentations
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Advertisements

Variations of the Turing Machine
2. Getting Started Heejin Park College of Information and Communications Hanyang University.
4 Control Statements: Part 1.
Chapter 1 C++ Basics. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-2 Learning Objectives Introduction to C++ Origins, Object-Oriented.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
By John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Programming Language Concepts
© Vinny Cahill 1 Writing a Program in Java. © Vinny Cahill 2 The Hello World Program l Want to write a program to print a message on the screen.
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Order of Operations Lesson
Chapter 11: Models of Computation
Turing Machines.
Lilian Blot 11 Spring 2014 TPOP 1. Lilian Blot 22 Spring 2014 TPOP 2.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Semantic Analysis and Symbol Tables
Lilian Blot CORE ELEMENTS PART I Python Language Autumn 2013 TPOP 1.
1 University of Utah – School of Computing Computer Science 1021 "Thinking Like a Computer"
How to convert a left linear grammar to a right linear grammar
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Lilian Blot PART III: ITERATIONS Core Elements Autumn 2012 TPOP 1.
© 2012 National Heart Foundation of Australia. Slide 2.
Lilian Blot PART V: FUNCTIONS Core elements Autumn 2013 TPOP 1.
Discrete Mathematics 3. MATRICES, RELATIONS, AND FUNCTIONS Lecture 5 Dr.-Ing. Erwin Sitompul
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
1 Variables and Data Types. 2 Variable Definition a location in memory, referenced by a name (identifier), where data of a given type can be stored, changed,
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
CS 240 Computer Programming 1
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Chapter Three Arithmetic Expressions and Assignment Statements
Analyzing Genes and Genomes
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Types of selection structures
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
1 Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1 Operators and Expressions.
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
COMP 14 Introduction to Programming
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Python Programming Chapter 2: Variables, expressions, and statements Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Introduction to Python
Introduction to Computational Linguistics Programming I.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
Input, Output, and Processing
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Variables, Expressions and Statements
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Programming In Python. Starter Using the internet… Find what a programming language is.
Topics Designing a Program Input, Processing, and Output
Variables, Expressions, and IO
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Presentation transcript:

Lilian Blot TO PROGRAMMING & PYTHON Introduction Autumn 2012 TPOP 1

Lilian Blot Declarative vs. Imperative Knowledge Declarative knowledge Statement of facts, does not tell you how to get to the fact, but does enable you to check the result is correct Imperative knowledge Tell you how to accomplish something, how to solve a problem, a kind of a recipe. Recipe to approximate the solution for example Autumn 2012 TPOP 2

Lilian Blot What is an Algorithm? An Algorithm is a description on how to perform a computation Instructions Flow of Control Termination Condition Does it converged? Find a solution A computation is the process of taking input and following a step-by-step algorithm to get a specific output. Autumn 2012 TPOP 3

Lilian Blot Computational Process A computational process, in a correctly working computer, executes programs precisely and accurately In other words: The computer will always do what you tell them to do. So if a program doesnt work it is YOUR fault. Autumn 2012 TPOP 4

Lilian Blot Types of Errors Crashes Never stops => infinite loop Runs to completion & produces the wrong answer Autumn 2012 TPOP 5

Lilian Blot What is a Program? Given a small set of instruction you can build any kind of program that you want Alan Turing showed that in fact there are 6 primitive instructions that are needed to do anything (computable) with a computer les/Turing's%20O-Machines.html les/Turing's%20O-Machines.html A Programming language, such as Python, provides a set of primitive functions Interpreter Is a program that can execute any legal set of instruction. Can be used to describe anything a computer can do Autumn 2012 TPOP 6

Lilian Blot What is a Program? A program is a sequence of instructions that specifies how to perform a computation. Few basic instructions are needed to write any kind of program: input: Get data from the keyboard, a file, or some other device. output: Display data on the screen or send data to a file or other device. math: Perform basic mathematical operations like addition and multiplication. conditional execution: Check for certain conditions and execute the appropriate sequence of statements. repetition: Perform some action repeatedly, usually with some variation. Autumn 2012 TPOP 7

Lilian Blot CORE ELEMENTS PART I Python Language Autumn 2012 TPOP 8

Lilian Blot A Powerful Programming Language Primitive expressions Represent the simplest entities with which the language is concerned Means of combination Compound expression are built from simpler ones Means of abstraction Compound objects can be named and manipulated as units Autumn 2012 TPOP 9

Lilian Blot Formal Language Formal Languages are language designed for specific application Python is a formal Language Python is unambiguous Python has strict syntax rules Syntax rules with regard to tokens, basic elements of the language Syntax rules with regard to structure, the way tokens are arranged in a statement Autumn 2012 TPOP 10

Lilian Blot Syntax & Semantic Syntax Tell us which sequence of characters and symbols constitute a well-formed string Static semantic Which well-formed strings have a meaning Semantics What that meaning is Programs have only one meaning, no ambiguity Autumn 2012 TPOP 11

Lilian Blot Values and Data Types A value is one of the fundamental things that a program manipulates A value can be: a letter L a word Lilian a number 1, 3.14, 1.2e3 (e.g ) and more complex data (seen later in the year) Values have a type, 1 and 1.0 are not represented the same way Autumn 2012 TPOP 12

Lilian Blot Values and Data Types Words and letters are strings ( str in Python) lilian blot or lilian blot Numbers with a decimal point are called float ( float ) 124.0, 124e2, Integer ( int ), number with no decimal point 1, 124, 0 Autumn 2012 TPOP 13 >>> type(Lilian Blot) >>> type(25) >>> type(190.0) Python shell

Lilian Blot Variables A critical aspect of programming is the means it provides for using names to refer to computational objects We say that the name identifies a variable whose value is the object Python uses the assignment statement = Autumn 2012 TPOP 14 >>> name = Lilian Blot >>> age = 25 >>> height_cm = Python shell

Lilian Blot Variables and Data Types Variables have types The type of a variable is the type of the value it refers to Autumn 2012 TPOP 15 >>> type(name) >>> type(age) >>> type(height_cm) Python shell

Lilian Blot State Diagram Autumn 2012 TPOP 16 Lilian Blot name age height_cm >>> name = Lilian Blot >>> age = 25 >>> height_cm = Python shell >>> print name Lilian Blot Python shell

Lilian Blot Variable Names variable names must start with a letter or an underscore variable names can contain letters, numbers and underscores variable names can be arbitrary long Python is case sensitive, so size and Size are two different variables by convention uppercase letters are not used multiple words names use underscore, e.g. book_title, book_price, … Autumn 2012 TPOP 17

Lilian Blot Variable Name and Keyword Languages rule and structure are defined by keywords Keywords cannot be used as variable names Autumn 2012 TPOP 18 andasassertbreakclasscontinuedefdel elifelseexceptexecforfinallyfromglobal ifimportinisnotlambdaorpass printraisereturntrywhilewithyield Pythons 31 keywords

Lilian Blot Statements & Expressions A statement is an instruction that the Python interpreter can execute An expression is a combination of values, variables, and operators Autumn 2012 TPOP 19 >>> Dr + name Dr Lilian Blot Python shell >>> name = Lilian Blot >>> print name Lilian Blot Python shell

Lilian Blot Operators Operators are special symbols that represent computations like addition and multiplication. The values the operator uses are called operands. As in Mathematics, when more than one operator appears in an expression, the order of evaluation depends on the rules of precedence. the result of * 2 is 11, not 14 Parentheses have the highest precedence the result of (3 + 4) * 2 is 14, not 11 use of parentheses is encouraged in long and complex expressions Autumn 2012 TPOP 20

Lilian Blot Operator Precedence OperatorName +, - Unary plus and minus (e.g. -10) ** Exponentiation *, /, //, % Multiplication, division, integer division, and remainder +, - Binary plus and minus (e.g. 3-10) = Assignment operators Autumn 2012 TPOP 21

Lilian Blot Composition Expression can be combined to create a more complex expression For example: operator (age * 10) + (height_cm / 100) print (Dr + name) +(>* 3) Autumn 2012 TPOP 22

Lilian Blot Assignment Operator However, the left-hand side of the assignment operator has to be a variable, not an expression Autumn 2012 TPOP 23 >>> Dr + name = title_name SyntaxError: can't assign to operator >>> Python shell

Lilian Blot Assignment and Expressions 24 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> name Lilian Blot >>> name = title + + name >>> name Dr Lilian Blot Python shell

Lilian Blot Assignment and Expressions 25 Autumn 2012 TPOP >>> firstname = Lilian >>> Python shell Lilian

Lilian Blot Assignment and Expressions 26 Autumn 2012 TPOP >>> firstname = Lilian >>> Python shell firstname Lilian

Lilian Blot Assignment and Expressions 27 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> Python shell firstname lastname title Lilian Dr Blot

Lilian Blot Assignment and Expressions 28 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> Python shell firstname lastname title Lilian Dr Blot Lilian + + Blot firstname lastname

Lilian Blot Assignment and Expressions 29 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> Python shell firstname lastname title Lilian Dr Blot Lilian Blot name

Lilian Blot Assignment and Expressions 30 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> name Lilian Blot >>> Python shell firstname lastname title name Lilian Dr Blot Lilian Blot

Assignment and Expressions 31 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> name Lilian Blot >>> name = title + + name Python shell firstname lastname title name Lilian Dr Blot Lilian Blot Dr Lilian Blot Dr + + Lilian Blot

Lilian Blot Assignment and Expressions 32 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> name Lilian Blot >>> name = title + + name >>> name Dr Lilian Blot Python shell firstname lastname title name Lilian Dr Blot Dr Lilian Blot

Lilian Blot Assignment and Expressions 33 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> name Lilian Blot >>> name = title + + name >>> name Dr Lilian Blot Python shell firstname lastname title name Lilian Dr Blot Lilian Blot Dr Lilian Blot

Lilian Blot Assignment and Expressions 34 Autumn 2012 TPOP >>> firstname = Lilian >>> lastname = Blot >>> title = Dr >>> name = firstname + + lastname >>> name Lilian Blot >>> name = title + + name >>> name Dr Lilian Blot Python shell firstname lastname title name Lilian Dr Blot Lilian Blot Dr Lilian Blot

Lilian Blot Summary What is a program Python a programming language Formal language with syntactic rules Values, Variables and Data Types Operators and the rules of precedence Autumn 2012 TPOP 35

Lilian Blot Quizzes Autumn 2012 TPOP 36

Lilian Blot Exercises Autumn 2012 TPOP 37