Skip to content

Commit eedcd79

Browse files
author
Andreas Kugel
committed
update at workshop
1 parent e6bfc1d commit eedcd79

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/2a-chessPrint.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@
3232
c = a % 3 # The is the modulo operation (reminder)
3333
d = 5 == 6 # d is False. The double "=" means "has equal value"
3434
35+
Block
36+
Every language has it's own syntax to form group of statements. Python
37+
uses indentation. All statements in sequence with the same indent level
38+
are in the same block, like so:
39+
if a == 4 then:
40+
thing1a() # call function thing1a in the IF branch
41+
thing1b() # same identation => same block => do also thing1b
42+
else: # same indent as the "if", previous block terminated
43+
thing2() # new block, do thing2 in the ELSE branch
44+
thing3() # not indented, previous block terminated. Thing3 is
45+
# outside the IF-ELSE block
46+
3547
Branch
3648
We test a condition and do one thing when it is true and another thing
3749
when it is false using IF ... ELSE ... statements like:
38-
if a == 4 then:
50+
if a == 4:
3951
do thing 1
4052
else:
4153
do thing 2
@@ -50,18 +62,6 @@
5062
while a < b:
5163
statements ...
5264
53-
Block
54-
Every language has it's own syntax to form group of statements. Python
55-
uses indentation. All statements in sequence with the same indent level
56-
are in the same block, like so:
57-
if a == 4 then:
58-
thing1a() # call function thing1a in the IF branch
59-
thing1b() # same identation => same block => do also thing1b
60-
else: # same indent as the "if", previous block terminated
61-
thing2() # new block, do thing2 in the ELSE branch
62-
thing3() # not indented, previous block terminated. Thing3 is
63-
# outside the IF-ELSE block
64-
6565
Function
6666
we use functions to execute code which is (re)used several times
6767
we can provide parameters to the functions, so the same code can
@@ -83,7 +83,7 @@ def segment(width, color):
8383
""" print <width> items of a color """
8484
# add items with a FOR LOOP
8585
for i in range(width):
86-
# print(color,end="") # simple verion
86+
#print(color,end="") # simple verion
8787
print("{0:2d}".format(color),end="") # this looks better
8888

8989
########################################################################
@@ -92,7 +92,7 @@ def main():
9292
"""create a checker board pattern using a function"""
9393

9494
# constants (actually just variables we do not change any more)
95-
fields = 8
95+
fields = 4
9696
fieldWidth = 4
9797

9898
# variables
@@ -103,7 +103,7 @@ def main():
103103
# we iterate until we are done ...
104104
while row < fields*fieldWidth and column < fields*fieldWidth:
105105
# print segment
106-
segment(fieldWidth,color)
106+
segment(fieldWidth, color)
107107
# invert color after every segment
108108
color = 1 if color == 0 else 0
109109
# increment column. go back to 0 after 8 fields

src/2b-chessList.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
def segment(width, color):
1313
""" put <width> items of color in a row"""
1414
# initialize a new list
15-
segment = []
15+
seg = []
1616
# add items with a FOR LOOP
1717
for i in range(width):
18-
segment.append(color)
18+
seg.append(color)
1919
# return the list
20-
return segment
20+
return seg
2121

2222
# the main function
2323
def main():

src/2c-chessNp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
def segment(width, color):
2323
""" put <width> items of color in a row"""
2424
# initialize a new list as a numpy array
25-
segment = np.empty(width) #
25+
seg = np.empty(width) #
2626
# add items with a FOR LOOP
2727
for i in range(width):
28-
segment[i] = color
28+
seg[i] = color
2929
# return the list
30-
return segment
30+
return seg
3131

3232
# the main function
3333
def main():
3434
"""create a checker board pattern using a function"""
3535

3636
# constants
37-
fields = 8
38-
fieldWidth = 2
37+
fields = 4
38+
fieldWidth = 4
3939

4040
# variables
4141
row = 0

src/4b-beadwork.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# google: https://www.google.com/search?q=algorithm+beadwork&tbm=isch
1313

1414

15-
#colors
16-
colors = ((255,255,255),(0,0,0),(255,0,0),(0,255,0))
15+
# colors
16+
colors = ((255, 255, 255), (0, 0, 0), (255, 0, 0), (0, 255, 0))
1717
# bead patterns
1818
bead5 = np.array(((0,0,1,0,0),(0,1,1,1,0),(1,1,1,1,1),(0,1,1,1,0),(0,0,1,0,0)))
1919
bead7 = np.array(((0,0,1,1,1,0,0),(0,1,1,1,1,1,0),(1,1,1,1,1,1,1),(1,1,1,1,1,1,1),(1,1,1,1,1,1,1),(0,1,1,1,1,1,0),(0,0,1,1,1,0,0)))
@@ -55,10 +55,10 @@ def mkThread(y,x, s, i, d, c):
5555

5656
mkBead(y,x+j*b,cl)
5757

58-
58+
5959
# image dimensions, depends on beads and triangle width
6060
W = 10 # triangle width in beds
61-
T = 8 # triangles in row,
61+
T = 8 # triangles in row,
6262
R = 4 # Triangle rows. multiple of 4, normally
6363
M = np.shape(bead)[0]*W*R # rows
6464
N = np.shape(bead)[1]*W*T # cols
@@ -100,7 +100,7 @@ def mkThread(y,x, s, i, d, c):
100100
p2 = f.add_subplot(212)
101101
p2.set_title("Process")
102102
p2.axis('off')
103-
103+
104104
################################
105105
# plot animation function
106106
def plotReplay(f):

0 commit comments

Comments
 (0)