Download ICS3 Exam Study Guide

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ICS3 Exam Study Guide:
Note: For Unit 9 Consult the last test and Unit 9 Makeup Quiz Assign.
Unit One
- Major Programming Languages
- Programming Key principals: Sequence, selection and repetition
- Artificial Inteligence and "the singularity"
- Hardware, speed (milli, micro, nano, pico, femto, atto, zepto) and capacity (Bit, Byte, Kilo,
Mega, Giga, Tera, Peta, Exa, Zetta, Yotta)
Units Two and Three
- Why use Python Why use Python?
- What is an interpreted language?
- What is a program?
- What is debugging?
- kinds of errors (Syntax errors, Runtime errors, semantic ( or logic) errors
- Formal and natural languages
Unit Four
- Variables, expressions and statements
- Values and types (str, int and float ie >>> type("Cowabunga") <type 'str'>)
- assignment statement creates new variables and gives them values
ie >>> message = "What's up, Doc?", >>> n = 17
- print statement
- Variable names
rules: - can contain both letters and numbers, but they have to begin with a letter.)
Although it is legal to use uppercase letters, by convention we don't. If you do, remember that
case matters. Bruce and bruce are different variables.
- underscore character (_) can appear in a name, no keywords allowed
- Python has twenty-nine keywords:
and
def
exec if
not
return
assert del
finally import or
try
break elif
for
in
pass
while
class else
from
is
print yield
continue except global lambda raise
- Statements (an instruction that the Python interpreter can execute)
- Expressions (a combination of values, variables, and operators)
- Operators and operands (special symbols that represent computations like addition and
multiplication)
(ie hour*60+minute minute/60 5**2 (5+9)*(15-7) )
-Comments # and '''
percentage = (minute * 100) / 60
- Destructive read in
- Concatenation
- Escape sequences (ie \n \t)
Unit Five
- Operators and functions for strings
a = b + c concatenate b and c
a = b * c b repeated c times
a[0] the first character of a
len(a) the number of characters in a
- String operations
- Slicing Strings
ie
aStr = "This is a string"
print aStr[0] #print T
print aStr[0:4] #print This
print aStr[:4] #print This
print aStr[10:] #print string
- length of the string
print len(aStr)
- input and raw_input commands
Unit Six
- Indentation
- Decisions ie if / elif / else
To compare things in Python:
a < b True if a is less than b
a <= b True if a is less than or equal to b
a > b True if a is greater than b
a >= b True if a is greater than or equal tob
a == b True if a is equal to b
a != b True if a is not equal to b
Most conditions are comparisons of one object with another.
A=3
B=4
if B > A:
print A # begin group
print B
print (A + B) # end group
A = 6 # not part of above group
print A
Note the difference between a double equal sign and a single one.
A == B -- used to determine if A and B are the same -- no change of values
A = B -- used to turn A in the same value as B -- changes of value are made.
- Combining conditions using and / or
- The defualt statement (when no others are true) ie else:
Unit Seven and Eight
Strings, Lists & Loops
- String Methods (most basic way to manipulate strings)
len(), replace(), count(), find(), split(), join(), upper(), lower(), capitalize(),
title(), swapcase(), isdigit(),isupper(),islower(),istitle(),isalnum(),isalpha(),
endswith(),append(), reverse(), remove(), sort()
- Lists: a variable-like object that can hold multiple pieces of information that are indexed
Example 1:
x=[‘A’,’B’ ,’C ‘,’D’]
print x[2] # will put C on the the screen – note a list index starts at 0
Example 2:
L = ['spam', 'Spam', 'SPAM!']
L[0:2] = ['eat', 'more'] # slice assignment: delete+insert
print L # replaces items 0, 1 ['eat', 'more', 'SPAM!']
Example 3: (break up a )
x=list('word')
print x
>>>['w', 'o', 'r', 'd']:
- Repetition: for loop
Example 1:
for count in range(1,11):
print count, # the comma is used to keep numbers on the same line
>>> 1 2 3 4 5 6 7 8 9 10
Example 2: (what happens with the range command:
>>> range(-32, -22) result: [-32, -31, -30, -29, -28, -27, -26, -25, -24, -23 ]
>>> range(5,21) result: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
>>> range(21,5) result: []
- for loop and accumulator (accumulators are used to add up numbers)
list = [2,4,6,8]
sum = 0
for num in list:
sum = sum + num # accumulator
print "The sum is:", sum
>>> The sum is: 20
- for loops are used to add items to an array (using append and to print out indicidual elements
using the loop index.
(see "bands example in tutorial)
- Random numbers: requires importing the random module
Example:
import random
pick = random.randint(1, 15) # selects one random integer from 1 to 15
print pick