Presentation is loading. Please wait.

Presentation is loading. Please wait.

SOPH 303 The Digital World Term 3 Spring 2013 Notes for Week 1. Sessions 2 and 3 Revised: January 28, 2013 Aditya Mathur Head of Pillar Information Systems.

Similar presentations


Presentation on theme: "SOPH 303 The Digital World Term 3 Spring 2013 Notes for Week 1. Sessions 2 and 3 Revised: January 28, 2013 Aditya Mathur Head of Pillar Information Systems."— Presentation transcript:

1 SOPH 303 The Digital World Term 3 Spring 2013 Notes for Week 1. Sessions 2 and 3 Revised: January 28, 2013 Aditya Mathur Head of Pillar Information Systems Technology and Design Singapore University of Technology and Design West Lafayette, IN, USA

2 Learning Objectives 210.009.2013. Week 1. Sessions 2 and 31/30/2013 Learn to use IDLE to write and execute Python programs Learn to use Python as a calculator: variables, arithmetic operations Understand basic object types: int, float, string, complex Learn how to import libraries Learn to print formatted and unformatted data Learn to use basic mathematical operations

3 Python installation Download Python if you have not yet done so. 310.009.2013. Week 1. Sessions 2 and 31/30/2013 Source for download: Go to: http: //epd-free.enthought.com/?Download=Download+EPD+Free+7.3-2 Click on EPD Free-Windows or EPD-Free Mac depending on your laptop When the download is complete click on the downloaded file and follow instructions to install.

4 Python installation: check 410.009.2013. Week 1. Sessions 2 and 31/30/2013 Go to the Enthought directory and click on IDLE. You should see a window with the message: Python 2.7.3 |EPD_free 7.3-2 (32-bit)| (default, Apr 12 2012, 11:28:34) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "copyright", "credits" or "license()" for more information. and a prompt like this: >>>

5 Python installation: Another check 510.009.2013. Week 1. Sessions 2 and 31/30/2013 Type: >>>import matplotlib You should see the prompt >>> indicating that matplotlib exists. More on this later.

6 Python: A simple exercise 610.009.2013. Week 1. Sessions 2 and 31/30/2013 Click on IDLE or just type idle in a terminal window. You should see a new window with the prompt >>> Go to the course web site and click on Sample Python Programs. Click on BasicExamplesWeek1 and then on simpleCalculator.py. Open a new window from the File menu in the Python window. Copy the code you just opened and paste in the new window.

7 Python: Program execution 710.009.2013. Week 1. Sessions 2 and 31/30/2013 Enter Function f5 in the new window you just opened. The program you just copied will be executed and the results will be in the Python window. Correlate the results with each line of the program to understand it. Look carefully at the comments in the program. After a small set of Python statements there will be a few simple exercises that you need to solve on your own. Once you have understood the entire program start working on problems in Problem Set 1.

8 Python: Types 810.009.2013. Week 1. Sessions 2 and 31/30/2013 Set of valuesSet of Operations x x x x x a b c

9 Python: Primitive types: int, long 910.009.2013. Week 1. Sessions 2 and 31/30/2013 -14 Set of integers Set of arithmetic operators 12 + - * 180 2010 1751 % sys.maxint: 9223372036854775807 -sys.maxint-1: -9223372036854775808 / // Long integers: unlimited precision Set of bitwise operators | << & >> ^ ~

10 Python: Primitive types: float 1010.009.2013. Week 1. Sessions 2 and 31/30/2013 3.14 Set of floating point numbers 12.77 180.0 2010.98135 -1751.0.2010E4 inf -inf nan Set of Operations (sample) + - * > == >= max: 1.7976931348623157e+308 min: 2.2250738585072014e-308 Epsilon: 2.220446049250313e-16

11 Python: Primitive types: complex 1110.009.2013. Week 1. Sessions 2 and 31/30/2013 Set of complex numbers 12.77+3j 1+2j 1.3j Set of Operations (sample) + - * > == >= -5 12.77-3j

12 Python: Primitive types: boolean 1210.009.2013. Week 1. Sessions 2 and 31/30/2013 Set of logical valuesSet of (logical) Operations (sample) and True False or not

13 Python: Names 1310.009.2013. Week 1. Sessions 2 and 31/30/2013 Used to denote variables, classes, objects Contain characters; must start with a letter, or an underscore (_) sign or an underscore. Examples: height, area1, Dog, _great_ Length unlimited, case sensitive. Dog and dog are different names. Our convention: All class names begin with an uppercase letter; all other names begin with a lower case letter.

14 Python: Constants 1410.009.2013. Week 1. Sessions 2 and 31/30/2013 A constant is something that cannot change during program execution. It is an immutable object. Examples: Integer constants: 0, 1, -1, +24, 29, 300009998, O14, 0x1B. 0b1011 Floating point constants: 0.0, -2.345e28, -0.000976512 Boolean constants: True, False String constants:,, Hi!, Alice in Wonderland

15 Python: Variables 1510.009.2013. Week 1. Sessions 2 and 31/30/2013 A variable is something whose value may change during program execution. Example: int numStudents; denotes the number of students whose grads have been processed. Its value changes as each students grade is processed by a grade processing program. Every variable has a name; its type is the type of its value. Example: hurricaneCategory=2; The name is hurricaneCategory and its type is int. The type of a variable may change when its value changes. Example: a=1 [Type of a is int] A=1.0 [Type of a changed to float]

16 Python: Strings and operations 1610.009.2013. Week 1. Sessions 2 and 31/30/2013 A string is any sequence of Unicode characters enclosed inside double or single quotes. Examples: ``Digital world, Digital world, ``, a=Digital b= world c=a+b The value of c is Digital world Several other formatting operations are available.

17 Python: Expressions 1710.009.2013. Week 1. Sessions 2 and 31/30/2013 Expressions are used to compute something. x=1; y=2; z=3.0 x*y+z; // Arithmetic expression, type of value float x<y; // Boolean expression, results in boolean value firstName=Mary, lastName= Jones; firstName+ +lastName; // Results in a String

18 Python: Assignment 1810.009.2013. Week 1. Sessions 2 and 31/30/2013 An assignment statement allows assigning the value of an expression to a variable. p=x*y+z; // p gets the value of x*y+z q=x<y; // q gets the value of x<y firstName=Mary, lastName= Jones; name= firstName+ +lastName;

19 Week 1. Sessions 2 and 3. 2013 Hope you enjoyed this week! 1910.009.2013. Week 1. Sessions 2 and 31/30/2013


Download ppt "SOPH 303 The Digital World Term 3 Spring 2013 Notes for Week 1. Sessions 2 and 3 Revised: January 28, 2013 Aditya Mathur Head of Pillar Information Systems."

Similar presentations


Ads by Google