Free Essay

Python Programming

In:

Submitted By calsoftware
Words 3768
Pages 16
Introduction to Programming with Python

1

Outline
Introduction to Python
Operators & Expressions
Data Types & Type Conversion
Variables: Names for data
Functions
Program Flow (Branching)
Input from the user
Iteration (Looping)
2

What is Python


Python is both an interpreted, general purpose, open source,

cross-platform,

high

level

programming language.


Python uses an interpreter. This is a software program that convert Python code to machine language. 

It is easy to jump in and experiment with
Python in an interactive fashion.

Compiling and interpreting


Many languages require you to compile (translate) your program into a form that the machine understands. compile source code
Hello.java



execute

byte code
Hello.class

output

Python is instead directly interpreted into machine instructions. interpret source code
Hello.py

output

4

Programming basics








code or source code: instructions in a program.

The

sequence

of

syntax: The set of legal structures and commands that can be used in a particular programming language. output: The messages printed to the user by a program. console: The text box onto which output is printed. 5

The Basic Pattern
Most of our programs will use the basic pattern of: 

Get some user input



Perform some algorithm on the input



Provide results as output

Identifiers in Python






Identifiers are names of various program elements in the code that uniquely identify the elements. They are the names of things like variables or functions to be performed.
In Python, identifiers


Are made of letters, digits and underscores



Must begin with a letter or an underscore



Examples: temperature, myPayrate, score2

Keywords


Keywords are reserved words that have special meaning in the Python language.
Because they are reserved, they can not be used as identifiers. Examples of keywords are if, while, class, import.

Reserved Words


You can not use reserved words as variable names / identifiers

and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print

Constants





Fixed values such as numbers, letters, and strings are called constants - because their value does not change
Numeric constants are as you expect
String constants use single-quotes (') or double-quotes (")
>>> print (123)
123
>>> print (98.6)
98.6
>>> print ('Hello world‘)
Hello world

Things to note about Python
1. Python is a calculator

2. A variable is a container

3. Different types cannot be compared

4. A program is a recipe

Python - A Calculator
How is it a Calculator?
Whenever you type an expression in form of numbers below, Python compute it and provide result 5
 3+4
 44/2
 2**3
 3*4+5*6
 If precedence is unclear, use parentheses
 (72 – 32) / 9 * 5

A variable is a container


A variable has:
 A name – identifier
 A data type - int, float, str, etc.

A variable is a container in which a data value can be stored within the computer’s memory.  The stored value can then be referenced using the variable’s name. For example, x=4 z=x*2


Sentences or Lines

x=2 x=x+2 print x

Assignment Statement
Assignment with expression
Print statement

Variable Operator Constant

Reserved Word

A variable is a container (1)


A variable must be assigned an initial value before using it in a sentence – See (2) below



You can change the contents of a variable in a later statement

x = 12.2 y = 14 + x x = 100

Right side is an expression.
Once expression is evaluated, the result is placed in (assigned to) y.

x 12.2 100 y 14

(2) p = 12.2 y = 14 + x

Python Variable Name Rules
Must start with a letter or underscore _
 Must consist of letters and numbers and underscores  Case Sensitive
 Good: spam eggs spam23 _speed
 Bad:
23spam #sign var.12
 Different: spam Spam SPAM


Assignment Statements


Multiple variables can be initialized with a common value in a statement, for example: a=b=c=8 

Alternatively, multiple variables can be initialised with differing values in a single statement using comma separators, for example: a, b, c = 1, 2, 3

In Python, you don’t have to specify the type of data a variable may contain in his declaration.
For example, int pet = 6

Numeric Expressions
Because of the lack of mathematical symbols on computer keyboards - we use computerspeak to express the classic math operations
 Exponentiation (raise to a power) looks different from in math.
Operators Operation
+
Addition
 Asterisk is multiplication


-

Subtraction

*

Multiplication

/

Division

%

Modulus

//

Floor Division

**

Exponent

Operator Precedence Rules


Highest precedence rule to lowest precedence rule



Parenthesis are always respected



Exponentiation (raise to a power)



Multiplication, Division, and Remainder



Addition and Subtraction



Left to right

Parenthesis
Power
Multiplication
Addition
Left to Right

Operator Precedence Rules
Now solve this expression x = 1 + 2 ** 3 / 4 * 5

>>> x = 1 + 2 ** 3 / 4 * 5
>>> print x
11
>>>

Parenthesis
Power
Multiplication
Addition
Left to Right

1 + 2 ** 3 / 4 * 5
1+8/4*5
1+2*5
1 + 10
11

Another Example
An expression is evaluated from the inside out (as shown below)


How many expressions are in this Python code? an expression

(72 – 32) / 9.0 * 5

values

(72 – 32) / 9.0 * 5
(40) / 9.0 * 5
40 / 9.0 * 5
4.44 * 5
22.2

Assignment Example
Before

X

3
Execute

Y

Z

5

12

Z=X*3+Z/Y

After

X

Y

Z

3

5

11

How an assignment is executed
1.
2.

Evaluate the right-hand side to a value
Store that value in the variable x = 2 print y = x print z = x print x = 5 print print print (x)
(y)
+ 1 z State of the computer:

x: 2 x: 5 y: 2

(x)
(y)
(z)

z: 3

Printed output:

2
2
3
5
2
3

To visualize a program’s execution: http://www.pythontutor.com/visualize.html#mode=edit Invisible TAB
Key in and run the following statements a=8 b=2 print(‘Addition:\t’, a, ‘+’, b, ‘=‘, a + b) print(‘Subtraction:\t’, a, ‘-’, b, ‘=‘, a – b) print(‘Multiplication:\t’, a, ‘x’, b, ‘=‘, a * b) print(‘Division:\t’, a, ‘/’, b, ‘=‘, a / b) print(‘Floor Division:\t’, a, ‘//’, b, ‘=‘, a // b) print(‘Modulus:\t’, a, ‘%’, b, ‘=‘, a % b)
The \t escape print(‘Exponent:\t’, a, ‘2 =‘, a + b)
Output
Addition:
Subtraction:
Multiplication:
Division:
Floor Division:
Modulus:
Exponent:

8 + 2 = 10
8–2=6
8 * 2 = 16
8 / 2 = 4.0
8 // 2 = 4
8%2=0
a2 = 64

sequence shown here adds an invisible tab character to format the output Assigning values
It is important to regard the = operator to mean
“assign” rather than “equals” to avoid confusion with the ‘==‘ equality operator.
Operator

Example

Equivalent

=
+=
-=

a=b a += b a -= b

a=b a = (a + b) a = (a – b)

*=
/=
%=

a *= b a /= b a %= b

a = (a * b) a = (a / b) a = (a % b)

//

a //= b

a =(a // b

**=

a**=b

a = (a**b)

Different types cannot be compared

Data Types


Every program must deal with data



The data is usually described as a certain type







This type determines what you can do with the data and how the data is stored
In Python basic types are integers (int), floating point (float), strings and Booleans
The first two are numeric and can be used in arithmetic, the last two are not

27

Data Types
Python has many native datatypes.
1.Booleans are either True or False.
2.Numbers can be integers (1 and 2), floats
(1.1 and 1.2), or even complex numbers.
3.Strings are sequences of Unicode, characters, e. g. an html document
4.Bytes and byte arrays, e.g. a jpeg image file.
5.Lists are ordered sequences of values.
6.Tuples are ordered, immutable sequences of values.
7.Sets are unordered bags of values.
8.Dictionaries are unordered bags of key-value pairs
28

Booleans
Python has a data type named bool which has 2 values, True and False.
These are actually representations of the values 1 and
0.
bool is a subclass of int and True / False are basically values that are being printed instead of 1 and 0, this has been done by overriding the repr and str methods of the bool class.
>>> truth = True
>>> truth + 1 # Woah!
2
>>>

29

Numbers
There are 3 distinct numeric types: integers, floating point numbers, and complex numbers.
Integers - A whole number. In theory any whole number from minus infinity to plus infinity, for example, -1, 0,123456
Floating Point Numbers - Any number that has digits after the decimal point, for example, 6.3 or -1.8. It may also be in scientific notation: 1.75e26.
Complex Numbers - This is a complex number consisting of two floats. Complex literals are written as a + bj where a and b are floating-point numbers denoting the real and imaginary parts respectively.
30

Strings
A string is any piece of text that does not distinguish between a string that is a single character. Python has two different string-types.
Normal Strings
You include a string in your program by surrounding it with single quotes or double quotes : x = "And so is this."
Multi-line = 'This is a string' y = strings can be denoted using triple quotes, ''' or """.
Unicode strings
Have an internal representation which keeps text as text. 31 x = u'A unicode string'

Bytes & Bytes Array
Bytes and byte arrays, e.g. a jpeg image file.

32

Lists
A list is a changeable sequence of data. A list is contained by square brackets i.e. [1,2,3]
>>> x = ["I", "Love", "Python"]
>>> x[2] = "BDC"
>>> print(x)
['I', 'Love', 'BDC']
The above code changes element number 2 in x.

33

Tuples
Tuples are a lot like lists in that they are used to store sequences of information.
Tuples are enclosed in parentheses ( ) where items are separated by commas and cannot be updated.
They are used to write-protect data and are usually faster than list as it cannot change dynamically.
Tuples can be thought of as read-only lists.

For example − tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
34

Sets
Set is an unordered collection of unique items.
Set is defined by values separated by comma inside braces { }. Items in a set are not ordered. For example, a
= {5,2,3,1,4}
We can perform set operations like union, intersection on two sets. Set have unique values. They eliminate duplicates. >>> a = {1,2,2,3,3,3}
>>> a
{1, 2, 3}
35

Dictionaries
Dictionary is an unordered collection of key-value pairs. Dictionaries contain a key and a value. { } enclose dictionaries. It is generally used when we have a huge amount of data.
Dictionaries are optimized for retrieving data.
We must know the key to retrieve the value.

Key and value can be of any type.
>>> d = {1:'value','key':2}
>>> d[1]
'value'
>>> d['key']
2

36

Operations behave differently on different types
3.0 + 4.0
3+4
3 + 4.0
"3" + "4"
3 + "4"
3 + True

# Error
# Insanity!

Moral: Python sometimes tells you when you do something that does not make sense.

4. A program is a recipe

What is a program?
A program is a sequence of instructions
 The computer executes one after the other, as if they had been typed to the interpreter
 Saving as a program is better than re-typing from scratch x=1 y=2 x+y print x + y print "The sum of", x, "and", y, "is", x+y


Comments


Often we want to put some documentation in our program. These are comments for explanation, but not executed by the computer. 

If we have # anywhere on a line, everything following this on the line is a comment – ignored Numerical Input


To get numerical input from the user, we use an assignment statement of the form

= input()


Here






would be replaced by a prompt for the user inside quotation marks
If there is no prompt, the parentheses are still needed Semantics




The prompt will be displayed
User enters number
Value entered is stored as the value of the variable

Example - Fahrenheit to Centigrade


We want to convert a Fahrenheit temperature to Centigrade.



The formula is

C = (F -32) x 5/9



We use type float for the temperatures.

Python Session

Exercise: Convert temperatures 




Make a temperature conversion chart:
Fahrenheit to Centrigrade, for -40, 0, 32, 68, 98.6, 212, 293, 451
Output:
-40 -40.0
0 -17.7778
32 0.0
68 20.0
98.6 37.0
212 100.0
293 145.0
451 232.778
You have created a Python program!
(It doesn’t have to be this tedious, and it won’t be.)

Print Statement


For output we use statements of the form print 



Semantics
 Value of expression is computed
 This value is displayed
Several expressions can be printed – separate them by commas

Print Statement


print : Produces text output on the console.



Syntax: print ("Message“) print (Expression)


Prints the given text message or expression value on the console, and moves the cursor down to the next line. print (Item1, Item2, ..., ItemN)





Prints several messages and/or expressions on the same line.

Examples: print ("Hello, world!“) age = 45 print ("You have", 65 - age, "years until retirement“)
Output:
Hello, world!
You have 20 years until retirement
46

Input Statement


input : Reads a number from user input.You can assign (store) the result of input into a variable.
Example:
age = input("How old are you? ") print ("Your age is“), age print ("You have“), 65 - age, "years until retirement"

Output:
How old are you? 53
Your age is 53
You have 12 years until retirement

47

Input
Exercise:


Write a Python program that prompts the user for his/her amount of money, then reports how many Nintendo Wiis the person can afford, and how much more money he/she will need to afford an additional Wii.

48

Text and File Processing

49

Strings






string: A sequence of text characters in a program.
 Strings start and end with quotation mark " or apostrophe ' characters.
 Examples:
"hello"
"This is a string"
"This, too, is a string. It can be very long!"
A string may not span across multiple lines or contain a " character.
"This is not a legal String."
"This is not a "legal" String either."
A string can represent characters by preceding them with a backslash.
 \t tab character
 \n new line character
 \" quotation mark character
 \\ backslash character


Example: "Hello\tthere\nHow are you?"

50

More expressions: strings
A string represents text
'Python'
myclass = "CSE 190p"
""

Empty string is not the same as an unbound variable
Operations:
 Length: len(myclass) 

Concatenation:
"Michael" + 'Ernst'



Containment/searching:
'0' in myclass
"O" in myclass

Indexes


Characters in a string are numbered with indexes starting at 0:


Example: name = "P. Diddy" index 1

character



0
P

.

2

3

4

5

6

7

D

i

d

d

y

Accessing an individual character of a string: variableName [ index ]


Example: print name, "starts with", name[0]
Output:
P. Diddy starts with P

52

String properties







len(string)

- number of characters in a string
(including spaces) str.lower(string) - lowercase version of a string str.upper(string) - uppercase version of a string
Example:
name = "Martin Douglas Stepp" length = len(name) big_name = str.upper(name) print (big_name, "has", length, "characters“)

Output:
MARTIN DOUGLAS STEPP has 20 characters
53

Text processing


text processing: Examining, editing, formatting text.




often uses loops that examine the characters of a string one by one

A for loop can examine each character in a string in sequence. 

Example: for c in "booyah": print c
Output:
b o o y a h 54

Strings and numbers


ord(text)








Example: ord("a") is 97, ord("b") is 98, ...
Characters map to numbers using standardized mappings such as ASCII and Unicode.

chr(number)


- converts a string into a number.

- converts a number into a string.

Example: chr(99) is "c"

Exercise: Write a program that performs a rotation cypher. 

e.g. "Attack" when rotated by 1 becomes "buubdl"
55

File processing




Many programs handle data, which often comes from files.

Reading the entire contents of a file: variableName = open("filename").read()
Example:
file_text = open("bankaccount.txt").read()
56

Line-by-line processing
Reading a file line-by-line: for line in open("filename").readlines(): statements Example: count = 0 for line in open("bankaccount.txt").readlines(): count = count + 1 print "The file contains", count, "lines."
 Exercise: Write a program to process a file of DNA text, such as:
ATGCAATTGCTCGATTAG
 Count the percent of C+G present in the DNA.


57

Repetition (loops) and Selection (if/else)

58

The for loop


for loop: Repeats a set of statements over a group of values.


Syntax: for variableName in groupOfValues: statements 





We indent the statements to be repeated with tabs or spaces. variableName gives a name to each value, so you can refer to it in the statements. groupOfValues can be a range of integers, specified with the range function.

Example: for x in range(1, 6): print x, "squared is", x * x
Output:
1 squared
2 squared
3 squared
4 squared
5 squared

is is is is is

1
4
9
16
25

59

range


The range function specifies a range of integers:




- the integers between start (inclusive) and stop (exclusive)

It can also accept a third value specifying the change between values.




range(start, stop)

range(start, stop, step) - the integers between start (inclusive) and stop (exclusive) by step

Example: for x in range(5, 0, -1): print x print "Blastoff!"
Output:
5
4
3
2
1
Blastoff!



Exercise: How would we print the "99 Bottles of Beer" song?
60

Cumulative loops


Some loops incrementally compute a value that is initialized outside the loop. This is sometimes called a cumulative sum. sum = 0 for i in range(1, 11): sum = sum + (i * i) print "sum of first 10 squares is", sum
Output:
sum of first 10 squares is 385



Exercise: Write a Python program that computes the factorial of an integer. 61

if


if statement: Executes a group of statements only if a certain condition is true. Otherwise, the statements are skipped.




Syntax: if condition: statements Example: gpa = 3.4 if gpa > 2.0: print "Your application is accepted."

62

if/else


if/else statement: Executes one block of statements if a certain condition is True, and a second block of statements if it is False.




Syntax: if condition: statements else: statements Example: gpa = 1.4 if gpa > 2.0: print "Welcome to Mars University!" else: print "Your application is denied."



Multiple conditions can be chained with elif ("else if"): if condition: statements elif condition: statements else: statements 63

while


while loop: Executes a group of statements as long as a condition is True.




good for indefinite loops (repeat an unknown number of times)

Syntax: while condition: statements 

Example: number = 1 while number < 200: print number, number = number * 2


Output:
1 2 4 8 16 32 64 128

64

Logic


Many logical expressions use relational operators:
Operator

Meaning

Example

Result

==

1 + 1 == 2

True

!=

does not equal

3.2 != 2.5

True

<

less than

10 < 5

False

>

greater than

10 > 5

True

= 5.0

True

Logical expressions can be combined with logical operators:
Operator

Result

and

9 != 6 and 2 < 3

True

or

2 == 3 or -1 < 5

True

not



Example

not 7 > 0

False

Exercise: Write code to display and count the factors of a number.
65

More expressions: Conditionals
22 > 4
22 < 4
22 == 4 x = 100
# Assignment, not conditional!
22 = 4
# Error! x >= 5 x >= 100 x >= 200 not True
Numeric operators: +, *, ** not (x >= 200)
Boolean operators: not, and, or
3 3): print(“You are a Car!”) else: print(“That's a LOT of wheels!”)
What's wrong with testing using the greater-than operator? 91

Input Example – possible errors from the input() function userName = input(“What is your name?”)
 userAge = int( input(“How old are you?”)
)
 birthYear = 2007 - userAge


print(“Nice to meet you, “ + userName)
 print(“You were born in: “, birthYear)


input() is guaranteed to give us a string, no matter WHAT the user enters.
But what happens if the user enters “ten” for their age instead of 10?

92

Input Example – possible errors from the input() function 












userName = raw_input(“What is your name?”) userAge = input(“How old are you?”) try: userAgeInt = int(userAge) except: userAgeInt = 0 birthYear = 2010 - userAgeInt print(“Nice to meet you, “ + userName) if userAgeInt != 0: print(“You were born in: “, birthYear )

The try/except statements protects us if the user enters something other than a number. If the int() function is unable to convert whatever string the user entered, the except clause
93
will set the userIntAge variable to zero.

Repetition can be useful!
Sometimes you want to do the same thing several times.
Or do something very similar many times.
One way to do this is with repetition: print 1 print 2 print 3 print 4 print 5 print 6 print 7 print 8 print 9 print 10
94

Looping, a better form of repetition.
Repetition is OK for small numbers, but when you have to do something many, many times, it takes a very long time to type all those commands.
We can use a loop to make the computer do the work for us.
One type of loop is the “while” loop. The while loop repeats a block of code until a boolean expression is no longer true.
Syntax:
while boolean expression :
STATEMENT
STATEMENT
95
STATEMENT

How to STOP looping!
It is very easy to loop forever: while True : print( “again, and again, and again”)

The hard part is to stop the loop!
Two ways to do that is by using a loop counter, or a termination test.
A loop counter is a variable that keeps track of how many times you have gone through the loop, and the boolean expression is designed to stop the loop when a specific number of times have gone bye.
A termination test checks for a specific condition, and when it happens, ends the loop. (But does not guarantee that the loop will end.)
96

Loop Counter






timesThroughLoop = 0

while (timesThroughLoop < 10): print(“This is time”, timesThroughLoop, the loop.”) timesThroughLoop = timesThroughLoop + 1

“in

Notice that we:

Initialize the loop counter (to zero)
Test the loop counter in the boolean expression (is it smaller than 10, if yes, keep looping)
Increment the loop counter (add one to it) every time we go through the loop

If we miss any of the three, the loop will NEVER stop! 97

While loop example, with a termination test

Keeps asking the user for their name, until the user types “quit”. keepGoing = True while ( keepGoing): userName = input(“Enter your name! (or quit to exit)” ) if userName == “quit”: keepGoing = False else: print(“Nice to meet you, “ + userName) print(“Goodbye!”) 98

Similar Documents

Premium Essay

Loops in the Python Programming Language

...What are the benefits of using loops in programming? Using the lecture and internet, research examples of loops in python and describe their functions. What is an example of a loop you might see in the real world? In programming, the use of loops allows a programmer to simplify repetitious tasks with a process that will repeat itself over a series of passed values whether it is form a user passed parameter or a store set of data (for example, pulling a set of data form a database and “looping” through it to perform a series of checks). The loop function in Python is called using the “for” statement where it will repeat a series of event in a sequence. The syntax in Python will be: for {element_to_repeat} in {sequence}: Do something here An example of this could be to output a user’s name on screen in a line break format such as: userName = ‘Paul’ for letter in UserName: print ‘Letter – ‘, letter print ‘That spells ‘, userName The use of loops in a real world example could be to validate if a series of values falls into a specific range. This may include something such as determining if a set of salaries was higher or lower than a national average. In a previous example, we wrote code that would determine how many years remained in a set of employees until they retired. In my work, I often use loops to run through a set of product serial numbers and determine if each one is in a manufacturer’s warranty or not prior to us shipping...

Words: 265 - Pages: 2

Premium Essay

Python Network Programming Cookbook

...www.it-ebooks.info Python Network Programming Cookbook Over 70 detailed recipes to develop practical solutions for a wide range of real-world network programming tasks Dr. M. O. Faruque Sarker BIRMINGHAM - MUMBAI www.it-ebooks.info Python Network Programming Cookbook Copyright © 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: March 2014 Production Reference: 1190314 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-346-3 www.packtpub.com Cover Image by Gabrielay La Pintura (linaza100@hotmail...

Words: 36383 - Pages: 146

Free Essay

Class Intro

...queues things are off about a person. I’m also very interested in the human brain and all the chemicals as humans we need to sustain life the reason is because I have a chemical imbalance. At age 5 I was diagnosed with ADHD primarily there’s other things that are their but we haven’t quite figured it out I have bits and pieces of Asperger’s and Autism but not enough to categorize me as “Autistic”, I view things differently I’m not on any meds anymore and its hard someday to focus because my mind is all over but then there are days were its just fine I’m hyper and get a lot done sometimes I let my hyper energy flow through my art work I do text effect pieces in Cinema 4D, Photoshop, and Illustrator and now messing around with Violent Python Programming I thoroughly enjoy the security side of IT because it’s all a puzzle and always staying on your feet to be 3, 5, 7 steps ahead of the black hats and getting inside there persona to start thinking like...

Words: 299 - Pages: 2

Free Essay

Raspberry Pi Car Creation

...Foulds Pi car Project 3 | AbstractThe purpose of this report is to give background information regarding IoT, Raspberry Pi, and Python as well as how these components were used to develop a system that would enable a user to control a RC car over a locally hosted website on any device with WiFi capability. The locally hosted website was created using HTML5 and CSS to format the layout of the website along with Javascript code to create and program buttons on the website. WebIOPi was used to convert the Javascript code to Python code to activate/deactivate the GPIO pins on the Raspberry Pi. Ruaan Klem 23653000 ITRW 324 | Pi car Project 3 | AbstractThe purpose of this report is to give background information regarding IoT, Raspberry Pi, and Python as well as how these components were used to develop a system that would enable a user to control a RC car over a locally hosted website on any device with WiFi capability. The locally hosted website was created using HTML5 and CSS to format the layout of the website along with Javascript code to create and program buttons on the website. WebIOPi was used to convert the Javascript code to Python code to activate/deactivate the GPIO pins on the Raspberry Pi. Ruaan Klem 23653000 ITRW 324 | Table of Contents 1. Introduction 2 2. The Internet of Things (IoT) 2 3. Raspberry Pi (RPi) 3 4. Python 4 5. System Development Methodology (SDM) 5 6. Development 6 7. Testing 11 8. Implementation 12 9. Experimentation 14 ...

Words: 4389 - Pages: 18

Free Essay

Hello

...www.it-ebooks.info OpenCV Computer Vision with Python Learn to capture videos, manipulate images, and track objects with Python using the OpenCV Library Joseph Howse BIRMINGHAM - MUMBAI www.it-ebooks.info OpenCV Computer Vision with Python Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2013 Production Reference: 1160413 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78216-392-3 www.packtpub.com Cover Image by Suresh Mogre (suresh.mogre.99@gmail.com) www.it-ebooks.info Credits ...

Words: 28138 - Pages: 113

Free Essay

Tesg

...java class loaders http://onjava.com/pub/a/onjava/2005/01/26/classloading.html 1. Bootstrap classes: the runtime classes in rt.jar, internationalization classes in i18n.jar, and others. Whenever a new JVM is started by typing java MyMainClass, the "bootstrap class loader" is responsible for loading key Java classes like java.lang.Object and other runtime code into memory first. The runtime classes are packaged inside of theJRE\lib\rt.jar file. 1. Installed extensions: classes in JAR files in the lib/ext directory of the JRE, and in the system-wide, platform-specific extension directory (such as /usr/jdk/packages/lib/ext on the Solaris™ Operating System, but note that use of this directory applies only to Java™ 6 and later). We can store extension libraries, those that provide features that go beyond the core Java runtime code, in the path given by the java.ext.dirs property. The ExtClassLoader is responsible for loading all .jar files kept in the java.ext.dirs path 1. The class path: classes, including classes in JAR files, on paths specified by the system property java.class.path. If a JAR file on the class path has a manifest with the Class-Path attribute, JAR files specified by the Class-Path attribute will be searched also. By default, the java.class.path property's value is ., the current directory. You can change the value by using the -classpath or -cpcommand-line options, or setting the CLASSPATH environment variable. The command-line options override...

Words: 295 - Pages: 2

Free Essay

Teams

...Abstract—The tremendous growth in popularity of smartphones has been closely matched by increased efforts to harness their potential. This has lead to the development of powerful mobile operating systems that provide novel programming platforms for the creation of rich mobile applications. To support these new paradigms, developers are now asked to spend considerable effort in replicating functionality, usually already available in web applications, for the native applications. In this paper, we observe that web applications closely simulate the design of native applications and the web origin can act as a more reliable authentication identifier for third-party application content.We consequently argue in favor of using web applications as the default for mobile platforms and propose a practical approach to extend web applications with native applicationlike capabilities. Central to our approach is a browser-based permission model that effectively manages permissions both at install time and at runtime, and supports dynamic user policies. We discuss security and non-security challenges of realizing this approach. The rapid growth of mobile computing and increasing adoption of smartphones has resulted in the evolution of rich mobile platforms, such as Android and iOS. While these platforms derive much of the functionality from traditional desktop operating systems, they also introduce security mechanisms to satisfy the new requirements imposed by the mobile ...

Words: 796 - Pages: 4

Free Essay

Program Design

...转:程序员练级之路 (作者:陈皓)作者: 吴江伟 建议: * 不要乱买书,不要乱追新技术新名词,基础的东西经过很长时间积累而且还会在未来至少10年通用。 * 回顾一下历史,看看历史上时间线上技术的发展,你才能明白明天会是什么样。 * 一定要动手,例子不管多么简单,建议至少自己手敲一遍看看是否理解了里头的细枝末节。 * 一定要学会思考,思考为什么要这样,而不是那样。还要举一反三地思考。 注:你也许会很奇怪为什么下面的东西很偏Unix/Linux,这是因为我觉得Windows下的编程可能会在未来很没有前途,原因如下:   * 现在的用户界面几乎被两个东西主宰了,1)Web,2)移动设备iOS或Android。Windows的图形界面不吃香了。 * 越来越多的企业在用成本低性能高的Linux和各种开源技术来构架其系统,Windows的成本太高了。 * 微软的东西变得太快了,很不持久,他们完全是在玩弄程序员。详情参见《Windows编程革命史》 所以,我个人认为以后的趋势是前端是Web+移动,后端是Linux+开源。开发这边基本上没Windows什么事。 启蒙入门 1、 学习一门脚本语言,例如Python/Ruby 可以让你摆脱对底层语言的恐惧感,脚本语言可以让你很快开发出能用得上的小程序。实践项目: * 处理文本文件,或者csv (关键词 python csv, python open, python sys) 读一个本地文件,逐行处理(例如 word count,或者处理log) * 遍历本地文件系统 (sys, os, path),例如写一个程序统计一个目录下所有文件大小并按各种条件排序并保存结果 * 跟数据库打交道 (python sqlite),写一个小脚本统计数据库里条目数量 * 学会用各种print之类简单粗暴的方式进行调试 * 学会用Google (phrase, domain, use reader to follow tech blogs) 为什么要学脚本语言,因为他们实在是太方便了,很多时候我们需要写点小工具或是脚本来帮我们解决问题,你就会发现正规的编程语言太难用了。 2、 用熟一种程序员的编辑器(不是IDE) 和一些基本工具 * Vim / Emacs / Notepad++,学会如何配置代码补全,外观,外部命令等。 * Source Insight (或 ctag) 使用这些东西不是为了Cool,而是这些编辑器在查看、修改代码/配置文章/日志会更快更有效率。 3、 熟悉Unix/Linux Shell和常见的命令行 * 如果你用windows,至少学会用虚拟机里的linux, vmware player是免费的,装个Ubuntu吧 * 一定要少用少用图形界面。 * 学会使用man来查看帮助 * 文件系统结构和基本操作 ls/chmod/chown/rm/find/ln/cat/mount/mkdir/tar/gzip … * 学会使用一些文本操作命令 sed/awk/grep/tail/less/more … * 学会使用一些管理命令 ps/top/lsof/netstat/kill/tcpdump/iptables/dd… * 了解/etc目录下的各种配置文章,学会查看/var/log下的系统日志,以及/proc下的系统运行信息 *...

Words: 817 - Pages: 4

Free Essay

Cassandra

...com/en/services/java.php Contact Artenum SARL, Technopôle Paris CyberVillage, 101-103 Bd Mac Donald 75019, Paris, France Phone: +33 (0)1 44 89 45 15 Fax: +33 (0)1 44 89 45 17 E-mail: contact@artenum.com http://www.artenum.com © Copyright 2003-2004 Artenum SARL, Paris, France. All Rights Reserved. 2 / 16 http://www.artenum.com Cassandra 2.0: Tutorial Table of contents Introduction! Key features! Pipeline viewer and editor Dynamic plug-ins system Dynamic object manipulation Cassandra architecture Cassandra GUI 5 5 5 5 5 5 6 Cassandra usage! Launching Cassandra Loading a VTK file Apply a simple filter Composition of filters Managing several scales and lookup tables Removing components Saving generated view Using the Python console Completion Accessing and changing the data Loading an...

Words: 1926 - Pages: 8

Free Essay

Intro to Communication Chapter 5 Reflection Paper

...CMST 192 2:00-3:15 pm - Dr. Fischer Chapter 5 Reflection Listening skills are a very important for each and every person to have. Without them, how is one able to understand another? We are all guilty of poor listening at some point, especially in this generation because of all the technology we have access to. Cell phones are one of the biggest distractions to listening that I have seen. A lot of times you will see students sitting on their phones during the middle of a lecture or even sitting on their phones at a dinner table rather than listening to what the people around them have to say. Other examples of reasons for poor listening are things like the effort a person is willing to put in, being overloaded with too much information at once, not knowing enough about the topic prior, just listening to respond and not actually taking what the person is saying into consideration or simply just not having respect for a person who may be speaking. There are many ways that a person can help themselves become a better listener such as reducing noise, putting in the effort to listen, stay focused on the conversation, try to have prior knowledge, avoid distractions and be respectful! I personally am someone who is very easily distracted by my phone during classes and that is something I am trying to work on because as soon as I put it away I will get so much more out of the classes I am taking. Noise doesn’t just have to be physical, it can be psychological which is what distracts...

Words: 387 - Pages: 2

Free Essay

Buisness

...Taking online classes and reaching one's maximum potential can be quite a challenge. In order to complete classes one must be able to set realistic goals and time-lines. A plan must be designed to incorporate work, family, and school. Last but not least, one must face the challenge of not physically being present in a classroom setting. Online classes can be a unique challenge, however; it is not impossible to successfully complete courses. Realistic goals and time-lines are almost always the key to being successful in anything one may do, online classes are no exception. Setting goals at the beginning of each course as to the grade one would like to achieve. Another goal that could be set is what does one want to learn and get out of the particular course. Tasks must be set in place for each day that the individual knows that they can accomplish. For instance, on day one of an assignment, complete all the necessary reading. Day two listen to any video lectures and read over instructor notes. Day three do homework and any class assignments. Day four review any notes that you have taken and the feedback form instructor as you are preparing for the test that week. Setting goals and time-lines help to keep you on track and where you need to be with the lesson. A plan must be designed to integrate school, work, and family to maintain an equal balance. Working and taking classes of any kind proves to be a challenge. Most people work at least 40 hour work weeks, but some people...

Words: 580 - Pages: 3

Free Essay

Communication Worksheet

...University of Phoenix Material Communication Styles Worksheet You spent the past few days exploring the resources available to students at University of Phoenix, and you want to share what you learned with a friend who is interested in enrolling. Write a 150- to 200-word e-mail to your friend summarizing the resources available to students. Hi Evelyn, How are you doing today? I am writing in regards to the resources available to students enrolled at the University of Phoenix. As you know, I have recently begun classes online. We have discussed the possibility of you returning to school. You have voiced concerns about not being able to write reports correctly or having enough time to complete classes. I had similar concerns before enrolling. There is a mandatory orientation class that students have to take before starting classes that introduces students to the online learning environment and all of the resources associated with the online learning center. I found the Center for Writing Excellence. This resource has tutorials that teach the proper way to format and write a paper. It also has a function that assists with citations. Also, there is a function that allows you to submit your paper to a tutor and they go over your paper before you turn it in and give advice on how to improve your paper. The Library is easy to navigate and there is the Ask a Librarian function for any questions you might have. The online classes make it easier...

Words: 547 - Pages: 3

Free Essay

Linux Vsc

...Contents Introduction 2 The Python Programming Language 2 History of Python 2 Features 4 Advantages and Disadvantages 5 Python vs. C 5 Summary 11 Bibliography 12 Introduction After comparing several programming languages, I have found many books and websites expressing how fast and efficient Python is. Further, many research papers describe the advantages of adding Python to computer sciences classes. For this reason I decided to study this language and compare it to one that I am familiar with, like the C language. This paper contains the history of Python, from its creation until now. It shows the features that make Python so popular, and the differences between Python and other languages. Most importantly, it explains the four pillars that are the foundation of the Python programming language, which are to provide quality, increase productivity, portability, and integration. Through this paper illustrate the advantages and disadvantages of Python, by showing that, although an interpretative language such as Python will never be as fast as a compiled language like C, it will be more efficient and useful in a variety of cases. The Python Programming Language History of Python Python (Software, 2011) is a relatively recent, object-oriented, interpreted scripting language created by Guido van Rossum at Stichting Mathematisch Centrum (CVI) in the Netherlands. According to Mark Pilgrim, Python is a successor of the ABC language...

Words: 1762 - Pages: 8

Free Essay

Pt1420 Unit 1 Rearch Ass.1

...Michael Campbell PT1420 Unit 1 Re Ass 1 10/10/2014 1. 1970s – The programming language was C, which was created by Dennis M. Richie. Before he created the C language there was the B language, which was created by Ken Thompson in 1969-70. The computers in that time wrote in assembly code and the user had to write many pages of code to do a task. When the B language was created, it made it possible to do a task in a few lines. Although the B language improved the systems it lacked use of structure and didn’t know data types. So in 1971-73 Dennis Richie wrote the C language in which he kept the B syntax but added data types and other changes that needed to be made. It was built for power and speed and developed for UNIX systems. Its also used for Windows, the MacOS and Linux. 2. 1980s – The programming language was Python, which was created by Guido van Rossum. It’s more of a scripting language and allows users to produce large quantities readable and functional code in a quick amount of time. Python teaches the user how to work with other languages, indentation, and modularity. It supports object – oriented, procedural, and functional program styles. C++ was also created and used many different types of computers. Program A was created by Arthur Whitney in 1988, and it focused on graphics, systems interfaces, utility support, and user community. 3. 1990s – The programming language was Ruby, which was created by computer scientist Yukihiro Matsumoto. It was created...

Words: 454 - Pages: 2

Free Essay

None

...00001101=13 * 00001000=8 * 00101011=43 3. Look at the ASCII chart in Appendix A on CD that accompanies this book and determine the codes for each letter of your name? * 67 97 114 108 111 115 78 97 106 101 114 97 * C a r l o s N a j e r a 4. Use the web to research the history of the BASIC, C++, Java, and Python programming languages, and answer the following questions? * Who was the creator of each language? * When was each of these languages created? * Was there a specific motivation behind the creation of these languages? If so, what was it? * Basic was created by John George Kemeny. It was created on 1964. * C++ was created by Bjarne Stroustrup. It was created on 1979. * Java was created by Dr. James A. Gosling. It was created on 1995. * Python was created by Guido van Rossum. It was created on 1991. * The motivation behind the development of computer programming languages such as C ++, Basic, Java, and Python is that once written, a function may be used several times without rewriting it over and over. Programming languages can be used to develop programs that control the performance of a machine and/or to convey algorithms...

Words: 259 - Pages: 2