ECET 49900 – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 1 Welcome! This is Professor Jai P. Agrawal. I will walk.

Slides:



Advertisements
Similar presentations
 2005 Pearson Education, Inc. All rights reserved Introduction.
Advertisements

COSC 120 Computer Programming
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to a Programming Environment
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Introducing Java.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Computational Linguistics Programming I.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
COMP 171: Principles of Computer Science I John Barr.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Input, Output, and Processing
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
Welcome To MOODLE Getting Started. Introductions Christa McLaughlin – High School math teacher and high school lead teacher of technology Jason Grubbs.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
Python Let’s get started!.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction to Programming
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
MET4750 Techniques for Earth System Modeling MET 5990 Techniques for Earth System Modeling and Research (
Module 1 Introduction to JavaScript
Introduction to Programming
Fundamentals of Programming I Overview of Programming
Introducing Python Introduction to Python.
Development Environment
CST 1101 Problem Solving Using Computers
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
Pamela Moore & Zenia Bahorski
Variables, Expressions, and IO
Introduction to Programming
Intro to PHP & Variables
CS190/295 Programming in Python for Life Sciences: Lecture 1
WEB PROGRAMMING JavaScript.
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Topics Designing a Program Input, Processing, and Output
Beginning Python Programming
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Input and Output Python3 Beginner #3.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 1 Welcome! This is Professor Jai P. Agrawal. I will walk with you to the exciting world of Python This is a course In designing a program using Python to perform a task on or through computer It is intended for beginners moving on to becoming professionals, that is, people who can produce systems that others will use –who are willing to work hard

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 2 Course Organization To access the course website go to Click on Spring Click on ECET – PythonECET – Python Log in with the username and password that you have received in the from the course administrator. Go to My profile in the left side bar and change your password. Save the username and the new password for future use. Enjoy all features of the website now while you are there. The course website is organized in a weekly format – 17 weeks with one week mid-semester recess. Download the following before you start this class: – and download Python Windows Installerhttp:// Windows Installer You must visit the class website on the scheduled dates and times of the class, which is 3 times a week. More visits are welcome. The lectures are posted in each week. There may be one or more activities in each week which may require submission by a due date. Submit your assignment etc. on the related activity only. All activities will be graded, a late submission will cost 20% of the grade. The submissions later than one week will be accepted but not graded. Read every Lecture on your pace, there are 3 lectures in every week, each 50 minutes long. Write your questions in the News Forum simultaneously wherein may be one of your co-students can answer for you. It is called horizontal learning. Write to your instructor if you have a question. You should get an answer within two days. It is called vertical learning.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 3 Python is a powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. By the way, the language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles. Python is simple to use, but it is a real programming language, offering much more structure and support for large programs than other programming languages such as C.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 4 Python offers much more error checking than C, and, being a very-high- level language, it has high-level data types built in, such as flexible arrays and dictionaries. Python allows us to split a large program into modules that can be reused in other Python programs. It comes with a large collection of standard modules that we can use as the basis of our programs — or as examples to start learning to program in Python. Python is an example of a high-level language. Two kinds of programs process high-level languages into low-level languages: interpreters and compilers.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 5 An interpreter reads a high-level program and executes it, meaning that it does what the program says. It processes the program a little at a time, alternately reading lines and performing computations. A compiler reads the program and translates it completely before the program starts running. In this case, the high-level program is called the source code, and the translated program is called the object code or the executable. Once a program is compiled, you can execute it repeatedly without further translation.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 6 Many modern languages use both processes. They are first compiled into a lower level language, called byte code, and then interpreted by a program called a virtual machine. Python uses both processes, but because of the way programmers interact with it, it is usually considered an interpreted language. I hope that you have downloaded all softwares necessary to go through this course. Python is a truly object-oriented languages. Python operates on objects using methods. Examples of Objects: Student, teacher, bolleyball, book etc. Examples of methods: exponent, power, squareroot, insert in a string, sort numbers and words etc. Objects have attributes and special methods. Objects have relatives and they interact with each other.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 7 Python organization: The python objects are organized as Packages: equivalent to directories Modules:equivalent to files such as.c,.cpp,.m in other languages Comprised of instructions to be executed in an order. The instructions are also called statements Functions:equivalent to functions, procedures or subroutines in other languages Methods:equivalent to operations in other languages A module is saved as xxx.py A module can be used as an object. There are some built-in modules such as math.py. A programmer can write own modules.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 8 We will use open source Python Integrated Development Environment (IDLE) for this course. There are two ways to use the Python interpreter: a) shell mode and b) script mode. In shell mode, you type Python statements into the Python shell in IDLE and the interpreter immediately prints the result. In script mode, you can write a program in a file and use the interpreter to execute the contents of the file. Such a file is called a script.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 9 First Python Program in Shell Mode Open the IDLE (PYTHON GUI) program, such as shown on the right: We will call this window as the Interpreter Window. Go back to the Interpreter and please keep it open throughout the lecture. The >>> is a prompt which appears in the interpreter window of the Python IDLE to prompt the user to enter a command (a python statement ) followed by a return. The python executes the statement and returns the result. To exit the Interpreter, type in the on the python prompt, press control key, press D while keep pressing the control key.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 10 The statement in the blue background is a python statement. Press at the end of the statement in the line. This program prints a string enclosed within single quotes (‘ ‘) or double quotes (“ “). Python is sensitive to indents, specially at the beginning of a line, therefore type in the statements exactly as given. A new statement opening with an indent (or more) will generate an error in the interpreter’s result. Let us write a welcome message in shell mode, enclosed in ‘…’: >>> print 'Hello Friends!! It is a wonderful world!!!' Hello Friends!! It is a wonderful world!!! The Python executes and returns the result, as shown in the yellow window below. If the string is longer than one line, it can be broken by adding a back slash ( \ ) at the end of line. However, the printed result continues without a break, does not introduce a new line, in the result. Try it out.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 11 More in the shell mode, >>> #Program to calculate the cost of apples >>> #the price of an apple is $0.20, find the cost of 25 apples. >>> price = 0.20# the price per apple >>> Number_apples = 25 >>> cost = price * Number_apples >>> print 'the cost of 25 apples is $', cost # print shell consists of a string and an \ expression involving a variable, separated by a comma. the cost of 25 apples is $ 5.0 The lines 1 and 2 are single-line comments, ignored by the interpreter. The comment line can have initial indent as in line 2. The comment line can also be after a python shell as shown in line 3 and line 6-7. Lines 4 and 5 are python shells, assign the value of expression to the right of = to the variable on the left. The variable name must not have any space in the middle. Words in a variable name can be joined using underscore ( _ ), but not a dash ( - ). The print shell can have any combination of strings and expressions, separated by commas. The interpreter returns the result as shown below:

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 12 Let us write a python script to do the same. Open file/new window (also called the new module window) and type in the following: #apples.py #the price of an apple is $0.20, find the cost of 25 apples. price = 0.20 Number_apples = 25 cost = price * Number_apples print 'the cost of 25 apples is $', cost >>> ================= RESTART ================================ >>> the cost of 25 apples is $ 5.0 The code in the module is given in green window. Python ignores any blank spaces in a line but does not want any indent at beginning of a line. Please do not add any indent carelessly. Save it as a module apples.py. Run it in the module window. The Python executes the whole file and presents the result in the Interpreter window, shown below in yellow.

ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 13 Exercise 1: Due Now. Write a python program in the script mode using a module to do the following: Calculate and print the area of a circle of radius = 4 meters, in square meters. Use the following formula: Area of circle = x radius * radius A break of 10 minutes. Try to write the code yourself. Come back and see my script. Multiple assignments are allowed like R=4; g=3 Or R, g = 4, 3