www.umbc.edu
CMSC201 Computer Science I for Majors
Lecture 15 – Program Design
- Prof. Katherine Gibson
- Prof. Jeremy Dixon
Based on slides from the book author, and previous iterations of the course
CMSC201 Computer Science I for Majors Lecture 15 Program Design - - PowerPoint PPT Presentation
CMSC201 Computer Science I for Majors Lecture 15 Program Design Prof. Katherine Gibson Prof. Jeremy Dixon Based on slides from the book author, and previous iterations of the course www.umbc.edu Last Class We Covered File I/O Input
www.umbc.edu
Based on slides from the book author, and previous iterations of the course
www.umbc.edu
2
www.umbc.edu
www.umbc.edu
4
www.umbc.edu
www.umbc.edu
6
www.umbc.edu
7
www.umbc.edu
8
www.umbc.edu
def nS(p, c): l = len(p) if (l >= 4): c += 1 print(p) if (l >= 9): return p, c # FUNCTION CONTINUES...
9
www.umbc.edu
def nS(p, c): l = len(p) if (l >= 4): c += 1 print(p) if (l >= 9): return p, c # FUNCTION CONTINUES...
10
www.umbc.edu
def nextState(password, count): length = len(password) if (length >= 4): count += 1 print(password) if (length >= 9): return password, count # FUNCTION CONTINUES...
11
www.umbc.edu
def nextState(password, count): length = len(password) if (length >= 4): count += 1 print(password) if (length >= 9): return password, count # FUNCTION CONTINUES...
12
www.umbc.edu
def nextState(password, count): length = len(password) if (length >= MIN_LENGTH): count += 1 print(password) if (length >= MAX_LENGTH): return password, count # FUNCTION CONTINUES...
13
www.umbc.edu
def nextState(password, count): length = len(password) if (length >= MIN_LENGTH): count += 1 print(password) if (length >= MAX_LENGTH): return password, count # FUNCTION CONTINUES...
14
www.umbc.edu
def nextState(password, count): length = len(password) if (length >= MIN_LENGTH): count += 1 print(password) if (length >= MAX_LENGTH): return password, count # FUNCTION CONTINUES...
15
www.umbc.edu
def nextState(password, count): length = len(password) if (length >= MIN_LENGTH): count += 1 print(password) if (length >= MAX_LENGTH): return password, count # FUNCTION CONTINUES...
16
www.umbc.edu
def nextState(password, count): length = len(password) # if long enough, count as a password if (length >= MIN_LENGTH): count += 1 print(password) # if max length, don't do any more if (length >= MAX_LENGTH): return password, count # FUNCTION CONTINUES...
17
www.umbc.edu
18
www.umbc.edu
19
www.umbc.edu
# check if car fits customer criteria if color == "black" and int(numDoors) > 2 \ and float(price) < 27000:
20
www.umbc.edu
# iterate over the list for item in myList:
# initialize the loop variable choice = 1 # loop until user chooses 0 while choice != 0
21
www.umbc.edu
# calculate tip and total - if more than # 5 guests, set percent to minimum of 15% if (numGuests > PARTY_OF_FIVE): percent = MIN_TIP tip = bill * percent total = bill + tip
22
www.umbc.edu
listFib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] listPrime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] # iterate over both lists, checking to see if each # fibonacci number is also in the prime list for num1 in listFib: for num2 in listPrime: if (num1 == num2): print(num1, "is both a prime and a \ Fibonacci number!")
23
www.umbc.edu
MIN_CH = 1 MAX_CH = 5 MENU_EX = 5 P1 = "X" P2 = "O"
24
# minimum choice at menu # maximum choice at menu # menu choice to exit (stop) # player 1's marker # player 2's marker
www.umbc.edu
www.umbc.edu
26
www.umbc.edu
27
Bad: def makeGrid(): temp = [] for i in range(0, 10): temp.append([0] * 10) return temp Good: def makeGrid(): temp = [] for i in range(0, GRID_SIZE): temp.append([0] * GRID_SIZE) return temp
www.umbc.edu
28
www.umbc.edu
www.umbc.edu
30
www.umbc.edu
31
www.umbc.edu
32
www.umbc.edu
www.umbc.edu
34
www.umbc.edu
35
www.umbc.edu
36
Big Idea
www.umbc.edu
37
Big Idea Part 1 Part 2 Part 3
www.umbc.edu
38
Big Idea Part 1 Part 2 Part 3 Part 2.A Part 2.B Part 2.C Part 3.A Part 3.B
www.umbc.edu
39
Big Idea Part 1 Part 2 Part 3 Part 2.A Part 2.B Part 2.C Part 3.A Part 3.B Part 2.B.1 Part 2.B.2
www.umbc.edu
40
Big Idea Part 1 Part 2 Part 3 Part 2.A Part 2.B Part 2.C Part 3.A Part 3.B Part 2.B.1 Part 2.B.2
www.umbc.edu
41
Big Idea Part 1 Part 2 Part 3 Part 2.A Part 2.B Part 2.C Part 3.A Part 3.B Part 2.B.1 Part 2.B.2
www.umbc.edu
42
Big Idea Part 1 Part 2 Part 3 Part 2.A Part 2.B Part 2.C Part 3.A Part 3.B Part 2.B.1 Part 2.B.2
www.umbc.edu
43
www.umbc.edu
www.umbc.edu
45
Big Idea Part 1 Part 2 Part 3 Part 2.A Part 2.B Part 2.C Part 3.A Part 3.B Part 2.B.1 Part 2.B.2
www.umbc.edu
46
www.umbc.edu
47
www.umbc.edu
48
www.umbc.edu
www.umbc.edu
50
www.umbc.edu
51
www.umbc.edu
52
www.umbc.edu
www.umbc.edu
54
www.umbc.edu
55
www.umbc.edu
56
www.umbc.edu
57
www.umbc.edu
58
www.umbc.edu
59
www.umbc.edu
60
www.umbc.edu
61 Based off a CMSC 104 exercise by Brooke Stephens
www.umbc.edu
62
Main Draw Chimney Draw Door Draw Windows Draw Outline
www.umbc.edu
63
Main Draw Chimney Draw Windows Draw Outline
Draw Door Frame Draw Knob
Draw Door
www.umbc.edu
Draw Window 3 Draw Window 2 Draw Window 1
64
Main Draw Windows Draw Outline
www.umbc.edu
65
www.umbc.edu
www.umbc.edu
67