 Recap – Python Basics. Python  Python is an interpreter which reads and executes a python script.  A python script is a text file, which contains.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
14/11/11.  These words have special meanings in themselves  These should NOT be used as Identifiers.  For example:  Break, do, function, case, else,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
Program Design and Development
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 8: Perl Basics Fundamentals of Web Programming.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Group practice in problem design and problem solving
Fundamentals of Python: From First Programs Through Data Structures
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Fundamentals of Python: First Programs
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Using Control Structures. Goals Understand the three basic forms of control structures Understand how to create and manage conditionals Understand how.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Input & Output: Console
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
 Expression Tree and Objects 1. Elements of Python  Literals, Strings, Tuples, Lists, …  The order of file reading  The order of execution 2.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
# ACS 168 Structured Programming Using the Computer Chapter 2 Spring 2002 Prepared by Shirley White.
Building Java Programs Primitive Data and Definite Loops.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
CSC 1010 Programming for All Lecture 1 Some material courtesy of Python for Informatics: Exploring Information (
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Language Find the latest version of this document at
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Chapter 7 JavaScript: Control Statements, Part 1
Information and Computer Sciences University of Hawaii, Manoa
Chapter 4 – C Program Control
Topic: Python’s building blocks -> Statements
ALGORITHMS part-1.
Topics Introduction to Repetition Structures
Primitive Data, Variables, Loops (Maybe)
Expressions and Control Flow in JavaScript
CS190/295 Programming in Python for Life Sciences: Lecture 1
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Algorithm Discovery and Design
Chapter 2 Programming Basics.
Tutorial 10: Programming with javascript
The Python interpreter
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

 Recap – Python Basics

Python  Python is an interpreter which reads and executes a python script.  A python script is a text file, which contains only text; no font, no style.  Once Python reads a file, it will execute the script line by line.  The order of execution is important to understand the behavior of the python script.

Analogy  Learning a computer program is similar to learning how to write and how to run a theatre play.

Analogy – Theatre Play  The script file is exactly the python script.

Analogy – Theatre Play  A programmer is a writer because the programmer writes a script.

Analogy – Theatre Play  The Python interpreter is a director because it interprets your script and controls the flow of execution as you intended.

Analogy – Theatre Play  Who is an actor?  There are operators and functions.

Analogy - Orchestra  You are a composer and Python is a conductor.

Analogy - Orchestra  A python script is a music score and each note is a literal (data).

Analogy - Orchestra  A music score can also have a loop though there is no counter nor conditions.

Analogy – Theatre Play  Flash Back  a device in the narrative of a motion picture, novel, etc., by which an event or scene taking place before the present time in the narrative is inserted into the chronological structure of the work.

Analogy Write a script. A director and actors practice together. The show opens in a theatre. Write a Python script. Python and operators test together. A program runs and produces an output.

Analogy  As a programmer, we are a composer or a writer.

Analogy  Our program is …

Analogy  Let’s not be fooled that we could write such a great master piece in this class or in a few days.

Analogy  The language of a theatre play is English.  The language of an orchestra is Music.  The language of a computer program is essentially Mathematics.  We have to be good at (at least) basic Mathematics.

Programming  Writing a program is a very complex activity that involves a different way of thinking.  Three things are different (at least):  Sequential order of Execution.  No automation; You should be very specific.  Different definition of operations; ( ‘=‘ for assignment, ‘==‘ for equality)

What we’ve learned  Literals: basic inputs  Numbers ( 3, 4, 3.2, 2.7 … )  String ( “hello”, ‘hi’, … )  Variable: a named storage or memory  Tuple: a composite data with an implicit form  (1,2), (“Name”, 3), …  List: a sequential container  [1,2,3], [“Hi”, “Every”, “One”], …

Statement  Direction to a computer which is interpreted by Python.  IF statement tests a condition (True or False)  While statement repeats while a condition meets.  For statement repeats for each element in a list/tuple/string

Even if we know those…  We have to know …  How to run a script?  How Python interprets your code?  What you want to do? What you want to compute?

Variable  A variable is a named storage or memory. L

Assignment Operator  ‘=‘ is used as assignment. a = 3  The assignment is an action to store a value into a variable.  The order of execution is from the right to the left.

Assignment Operator a = 1 a = a + 1

Assignment Operator  The assignment operator always move from the right to the left.  The left always has to be a destination. a + 1 = a

Python handles the RHS.  Python evaluates the expression which appear in the right hand side. A = Memory A

Python handles the RHS. A = 3 A = A + 1 Memory A 3 Your Code 3

Python handles the RHS. A = A A Memory A 3 3 4

Expression  A structure for evaluation is called ‘Expression’. + 1A 3 4

Expression  Expression is like an equation in Mathematics.  With an operator and operands (data), Python reduces an expression into a value.  For example, transforms into 7.  For example, “Hello” + “, World” changes into “Hello, World”

Note that  The result of operations is different between types! 7+8  15 “Alpha”+”bet”  ”Alphabet” 7/2  3 but 7 / 2.0  3.5

Assignment Operator  The mover can move the result only after the expression is evaluated.

Let’s see what Python doing A = 1 B = 2 A = A + 1 B = A + B A = A + B B = A + B A = A + B

Change of Flows  A Music sheet also has non-conditional loops

IF Statement  IF statement is a branch with a certain condition.  IF statement has a block of code to execute. Code to Execute With True

Conditional Expression 1. A = True 2. B = False 3. C = 3 == 4 4. D = (3+2) > 5 5. F = 3 in [1,2,3] 6. If D: X = 0

While Loop  When Python reads a WHILE statement, it will repeat a block of code within the WHILE statement. 1 I = 0 2 WHILE I < 3: 3 I = I + 1 The order of execution is 1 [ 2 3 ] [ 2 3 ] [ 2 3 ]

FOR Statement  When Python reads FOR statement, it will bring up each element in a list/tuple/string one by one. 1.A = 0 2.FOR x IN [1,2,3]: 3. A = A + x The order of execution is 1 [2 3] [2 3] [2 3]

A Program  Let’s write our own program.  Imagine as if you are the writer or the composer.  You have to know about characters very well (operators).  You have to know about what you want to convey (execute).

Practice 1  Summation  What if?

Practice 2  Test if N is a prime

Practice 2  If there is any zero in L, then N is not a prime.

Homework  Due is a week.  The homework should be submitted by 28 th May.  The late homework will not be scored.  I will announce how to submit your homework on next Tuesday.