lecture 4 functions. 2 codecademy 4.a. 3 codecademy: comments. as parameter of a function second...
TRANSCRIPT
![Page 1: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/1.jpg)
Lecture 4
Functions
![Page 2: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/2.jpg)
2
CodeCademy 4.a.
![Page 3: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/3.jpg)
3
CodeCademy: comments.
As parameter of a function
Second way to introduce variables:
What do max, min, abs do on text strings?
What if you switch the order of a print and return at the end of a function definition?
![Page 4: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/4.jpg)
4
Careful: 18 refers to (* args) , but we met this before
Ex. 19: different ways to call functions Ex. 21: watch the order of evaluation !
LPTHW: 18, 19 and 21
![Page 5: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/5.jpg)
5
![Page 6: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/6.jpg)
6
Recursive functions:
def countdown(n):if n > 0:
print "I'm counting down, now at %d." % n
countdown(n-1)elif n == 0:
print "Happy New Year!"
countdown(5)countdown(10)
![Page 7: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/7.jpg)
7
And countup:
def countup(n):if n > 0:
countup(n-1) print "I'm counting down, now at %d." % n
elif n == 0:print "Happy New Year!"
countup(5)countdown(10)
Weird !!!
![Page 8: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/8.jpg)
8
And infinitecount:
def infinitecount(n):print "I'm still %d !" % ninfinitecount(n)
infinitecount(10)
![Page 9: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/9.jpg)
9
Turing complete programming languages.
Allow to compute _any_ computable function.
comparison (==, !=, <, >, <=, >=) + Math (+, -, *, /) + If + functions
Are Turing complete. Anything that can be done with “for”- or
“while”- loops, can also be done with recursion.
![Page 10: Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments. As parameter of a function Second way to introduce variables: What do max, min,](https://reader036.vdocuments.mx/reader036/viewer/2022082418/5697c0101a28abf838ccb248/html5/thumbnails/10.jpg)
10
Assignment for next week:
CodeCademy 5.a Lists and Dictionaries (31 min), 5.b A day at the supermarket (28 mins):
LPTHW Ex.32 (9 min), Ex. 34 (11 min)
Ignore all the long comments on ordinals/cardinals.