0% found this document useful (0 votes)
3 views3 pages

Programming Final

The document provides a comprehensive overview of computer architecture, including the components and functions of computers, memory types, and peripheral devices. It also covers programming concepts such as data types, algorithms, control structures, and Python programming syntax. Additionally, it explains the use of functions, methods, and data structures in programming.

Uploaded by

jiayiduan2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Programming Final

The document provides a comprehensive overview of computer architecture, including the components and functions of computers, memory types, and peripheral devices. It also covers programming concepts such as data types, algorithms, control structures, and Python programming syntax. Additionally, it explains the use of functions, methods, and data structures in programming.

Uploaded by

jiayiduan2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Jia Yi Duan 2430435

Programming Final Exam

Computer info: computer=electronic device that stores and processes data (binary form), important bc
fast, accurate, consistent, reliable. Computers aren’t smart, smartness contained in the software that runs
at a given momentrely on programmers and operators. Von neumann architecture: Cpu most important
part of computer, memory =electronic component that stores instructions, data to be processed, results.
Peripherals=components that allow it to interact with humans ex: keyboard, screen, mouse
Central processing unit: control unit=component coordinate all activities of the processor, arithmetic logic
unit=performs arithmetic/logic operations, registers=small amounts of high-speed memory contained in
the CPU (CPU does calculations, input/output, memory access and management)
Memory: RAM main memory and ROM=store data can only be read, advantages of RAM compared to
ROM: more storage capacity, faster, read-write operators. Disadvantages: volatility. Advantages of ROM
compared to RAM: non-volatile memory,
Peripherals: input devices=allow provide data/instructions/control signals to computer ex: keyboard,
pointing devices like mouse, touchpad, trackball, trackpoint, scanner. Output devices=receives data from
system and convert into human-readable form ex: monitor, printers (inkjet=uses liquid ink, laser=uses
laser beam and powder ink), speakers. Input/output devices=hardware device that accepts inputted,
outputted or other data ex: touchscreen(smartphone) and permanent storage devices (3
categories=magnetic, optical, electronic def: computer data storage device that retain their data when
they are unpowered). magnetic= Hard disk drive, floppy disk (slow for today’s data). Optical=CD, DVD.
Electronic=USB flash drive, SSD vs HDD. Cache memory=RAM cache=used to speed up access to CPU,
more expensive than RAM
T1&2: Computer= performs calculations, remembers results, programs=software (easily changed), Binary
(base2): 1022=1*2^2+0*2^1+2*2^0, Decimal (base10): 10210=1*10^2+0*10^1+2*10^0, mutable
=lists, dictionaries immutable= tuples
T3: Linear search=checks each element in the list one by one until the desired element is found ->useful
sorted or unsorted small dataset, Binary search=efficient algorithm -> must be sorted. It repeatedly
divides the search interval in half, comparing the target value to the middle element of the list (useful for
large data set) 2 types or algorithms: declarative “the capital of Canada is Ottawa” and imperative “drive
from Ottawa to Halifax”
T4: Numeric value/literal: integers(int)=exact, whole numbers (1,1234,0b10100): floating point (float):
fractional num, inexact (1.0, 1E6) Float div: 10/4=2.5; floor div: 10//4=-2 ; 10.0//4.0=2.0, -10//4=-3 ;
remainder (modulo): 10%3=1 a-(a//b)*b
If either operand is a float, the result is a float; single-dash div always give float; expo with exponent
<0 gives float; != means not equal, Operator precedence: Expo, mult/div, add/sub, relational operators
(<,>), bool not, and or; parentheses (..) force desired order: 2**2**3 equals 256(2^3=8) (2^8=256);
strings (str) “a” <”b” true, “a”>”Z” true,“B”> “A” true; built-in functions: print, input, max, min,
abs( absolute value), round (float to integer)
T5: Python statements: names can’t start with a number and can’t be a keyword/reserved word;
Reserved words: and, as, assert, class, def, elif, if, else, except, False, True, for, from, import,
while, in, not, or, return; Assignment: = acts as an arrow,
If statement expresses alternation, if the statement is true, run the statement list (body), otherwise skip
to the statement after the if, Elif clause: if clause’s expression is true, its body runs, no more action is
taken once a body runs, else clause: the else body runs only if none of the prior bodies ran, while
statement defines an iteration (loop), *n% i==0  i divides n evenly
T6: Imports: import math; print (math.pi, math.sin (0)) OR from math import *; print (pi, sin (0)) OR import
random as rnd; print(rnd.random())
T7: Lists: [10,5,11] or [‘red’, ‘green’] or [true, false]mutable sets, dictionary VS immutable=integer,
float, Bool, string, tuples, range, Built-in function len(): length= print(len(“apple”))=5 or
print(len([9,10,11]))=3, Indexing (starts at 0!): text = "abcde" ; n = 1; char = text[n+1] >>> print(char,
len(char))=c1 ,Slicing: ls = [1.5, 2.1, 1.7, 0.9, 3.2, 2.2, 2.5]; ls[0:4:2]=[1.5,1.7] (exclude the last value and
keep one, skip one); ls[::3]=[1.5,0.9,2.5]
Jia Yi Duan 2430435
T8: Boolean: any str, tuple or list of length zero (an empty container), the numbers 0 or 0.0, none, will
convert to False, Short-circuit: A and B. If A is False, the whole expression is False for any value of B. So,
Python doesn't even evaluate B. Compare A or B, if A is true, there is no need to evaluate B. not and or

T9: Augmented assignment: i=i+1 is equal to i+=1, x**=2 is equal to x=x**2, y-=z is equal to y=y-z,
q//=d is equal to q//d, nested list= list in a list, matrix=[[1,2],[3,4],[5,6]], matrix[1][0]=3, For loop: repeat
code for every element in a sequence, Array=[5,3,4,0,2] for value in array: print(value, value**2) 5,25; 3,
9; 4, 16; 0,0; 2, 4; For loop and range: For index in range(4): print(index)0,1,2,3

T10: Functions(procedures) are basic units of program constructions, def statementthe statement list is
the function body, name used to call function

T11: The assert statement evaluates the expressionif expression is True, nothing happens but if
expression is False, an exception is raised.

T12: for mutable objects ex list, methods tend to update objects in place and not return anything ex:.
sort(), for immutable objects ex strings, methods cannot update objects in place therefore has to return
something,

string methods: s.strip(), s.split(), s.upper(), s.lower(), s.replace(v, w), s.index(), s.rindex(), s.find(),
s.rfind(), [s.isupper()=uppercase, s.islower()=lowercase, s.isalpha()=letters, s.isdigit()=digits,
s.isalnum()=alphanumeric]= true if s consists…

list methods: x.append(), x.clear(), x.copy(), x.count(), x.index(i,v)=add value v to x at index i,


x.reverse(), x.insert(), x.pop()=remove final ele of v, x.remove(v), x.sort()

T13&14: d.keys()=get keys only, d.values()=get values only, d.items()=get items, d.copy()=create a copy,
d.pop(k)=remove key k, d.get(k, v)= get value for k if present, otherwise return v. len(d) =gives number of
items in dict d
Jia Yi Duan 2430435

You might also like