Class Notes (1,100,000)
CA (620,000)
UW (20,000)
CS (1,000)
CS234 (30)
Lecture 1

CS234 Lecture Notes - Lecture 1: Quicksort, Trie, Long Term Ecological Research Network


Department
Computer Science
Course Code
CS234
Professor
John- Paul Pretti
Lecture
1

This preview shows pages 1-3. to view the full 206 pages of the document.
Example0.py!
!
- results of evaluation are printed in automatically only when programs are
run in the shell (not as a script)!
!
Example1.py (football)!
!
- 6 points per touch down!
- 1 point per 10 yards!
!
LEC 02 09/10!
!
don't use python 3!
!
A1 is going to be posted soon | expecting 4 questions!
Due in 2 weeks!
Will use public test!
Markus will be ready soon!
Bonus in every assignment!
!
Python recap:!
!
raw_input(prompt) is a built-in function and prompt can be left blank.!
reads what is input by the user and produce it as a string.!
!
>>>raw_input()!
234!
returns '234' which is a string!
!
int() converts a string to an integer, also floors a number int(5.7) -> 5!
int('234') -> 234!
int('one') -> error!
!
+ 连接 strings!
!
print prints an output, used in programs that require interaction with user.!
!
print is dierent from produce.!

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

!
str() converts to string!
!
be careful with / division!
!
7/2 => 3!
7.0/2 => 3.5!
7/2.0 => 3.5!
!
be careful with floating point operation and comparisons. try using int if
possible!
!
(.1+.1+.1)==3 is false since .1 is in fact 0.1000000...01 in python due to
number of digits stored.!
!
float(): float operation!
!
int(5.7) floors the number: rounds down to 5!
!
white space matters in python!
!
python convention: use _ and not capital letters.!
!
Example 2 (similar question on A1)!
!
focus: function, ifs, loops!
!
(to display the output correctly, change the font in UI: general to!
monospace)!
!
in shell:!
>>> print_diamond(5)!
should give a diamond shape. 5 is dimension:!
!
how to approach the loop:!
break down into small loops: print top part, print middle row, print lower
part. loop print loop!
!

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

!
'string'*7 prints a big string that repeats the string 7 times.!
(A handy feature in python)!
!
guessing game eg2!
!
import random!
random is a package to import to use the random.randint() function,
which generates a random number.!
!
do not forget : in the while loops and if else!
!
!
2014/09/12 Lec 03!
!
More python!
!
every fcn in python returns a value (value or None)!
def f(x)!
print 'here'!
return x!
run in the shell f(7) gives !
here!
7!
!
def f(x)!
print 'here'!
x!
!
in the shell:!
print f(x)!
gives!
here!
None!
!
since x is not returned.!
!
Example 2 guess a number!
You're Reading a Preview

Unlock to view full version