www.umbc.edu
CMSC201 Computer Science I for Majors
Lecture 13 – Functions
- Prof. Katherine Gibson
Based on concepts from: http://mcsp.wartburg.edu/zelle/python/ppics2/index.html
CMSC201 Computer Science I for Majors Lecture 13 Functions Prof. - - PowerPoint PPT Presentation
CMSC201 Computer Science I for Majors Lecture 13 Functions Prof. Katherine Gibson Based on concepts from: http://mcsp.wartburg.edu/zelle/python/ppics2/index.html www.umbc.edu Last Class We Covered Midterm exam Comments?
www.umbc.edu
Based on concepts from: http://mcsp.wartburg.edu/zelle/python/ppics2/index.html
www.umbc.edu
2
www.umbc.edu
3
www.umbc.edu
4
www.umbc.edu
www.umbc.edu
6
www.umbc.edu
7
bash-4.1$ python test.py 5 <class 'int'> bash-4.1$
www.umbc.edu
8
www.umbc.edu
9
www.umbc.edu
10
www.umbc.edu
www.umbc.edu
def main(): print("Happy birthday to you!") print("Happy birthday to you!") print("Happy birthday, dear Fred...") print("Happy birthday to you!")
>>> main() Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred... Happy birthday to you!
12
www.umbc.edu
13
www.umbc.edu
14
www.umbc.edu
def singFred(): happy() happy() print("Happy birthday, dear Fred...") happy()
15
www.umbc.edu
def happy(): print("Happy birthday to you!") def singFred(): happy() happy() print("Happy birthday, dear Fred...") happy() def main(): singFred() # sing Happy Birthday to Fred main()
16
www.umbc.edu
17
www.umbc.edu
18
www.umbc.edu
def happy(): print("Happy birthday to you!") def singFred(): happy() happy() print("Happy birthday, dear Fred...") happy() def singLucy(): happy() happy() print("Happy birthday, dear Lucy...") happy() def main(): singFred() # sing Happy Birthday to Fred print() # empty line between the two singLucy() # sing Happy Birthday to Lucy main()
19
www.umbc.edu
20
www.umbc.edu
21
www.umbc.edu
www.umbc.edu
def sing(person): happy() happy() print("Happy birthday, dear", person + "...") happy()
23
www.umbc.edu
def happy(): print("Happy birthday to you!") def sing(person): happy() happy() print("Happy birthday, dear", person + "...") happy() def main(): sing("Fred") print() sing("Lucy") main()
24
www.umbc.edu
def happy(): print("Happy birthday to you!") def sing(person): happy() happy() print("Happy birthday, dear", person + "...") happy() def main(): sing("Fred") print() sing("Lucy") main()
25
www.umbc.edu
26
www.umbc.edu
27
www.umbc.edu
28
www.umbc.edu
29
www.umbc.edu
www.umbc.edu
31
www.umbc.edu
32
www.umbc.edu
33
www.umbc.edu
34
www.umbc.edu
35
www.umbc.edu
36
www.umbc.edu
37
www.umbc.edu
www.umbc.edu
39
www.umbc.edu
40
www.umbc.edu
41
www.umbc.edu
def happy(): print("Happy birthday to you!") def sing(person): happy() happy() print("Happy birthday, dear", person + "...") happy() def main(): sing("Fred") print() sing("Lucy") main()
42
www.umbc.edu
43
www.umbc.edu
44
def main(): sing("Fred") print() sing("Lucy") def sing(person): happy() print("Happy BDay", person) happy() happy()
www.umbc.edu
45
def main(): sing("Fred") print() sing("Lucy") def sing(person): happy() print("Happy BDay", person) happy() happy() person = "Fred" person: "Fred"
www.umbc.edu
46
www.umbc.edu
47
def main(): sing("Fred") print() sing("Lucy") def sing(person): happy() print("Happy BDay", person) happy() happy() person = "Fred" person: "Fred" def happy(): print("Happy BDay to you!")
www.umbc.edu
48
www.umbc.edu
49
def main(): sing("Fred") print() sing("Lucy") def sing(person): happy() print("Happy BDay", person) happy() happy() person = "Fred" person: "Fred" def happy(): print("Happy BDay to you!")
www.umbc.edu
50
www.umbc.edu
51
www.umbc.edu
52
def main(): sing("Fred") print() sing("Lucy") def sing(person): happy() print("Happy BDay", person) happy() happy() person = "Lucy" person: "Lucy"
www.umbc.edu
www.umbc.edu
54
www.umbc.edu
def sing(person, age): happy() happy() print("Happy birthday, dear", person, "...") print("You're already", age, "years old...") happy()
55
www.umbc.edu
56
Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred... You're only 46 years old... Happy birthday to you!
www.umbc.edu
57
www.umbc.edu
58
Happy birthday to you! Happy birthday to you! Happy birthday, dear 46... You're only Fred years old... Happy birthday to you!
www.umbc.edu
59
www.umbc.edu
www.umbc.edu
61