-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathch_4_comma.py
56 lines (33 loc) · 980 Bytes
/
ch_4_comma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Comma Code
def commaFun(useList):
if len(useList) == 0:
return useList
ret = ''
for i in range((len(useList) - 1)):
ret += useList[i] + ', '
ret += 'and ' + useList[len(useList) - 1]
return ret
spam = ['apples', 'bananas', 'tofu', 'cats']
#print(commaFun(spam))
#print(commaFun(['a', 'b', 'c', 'd']))
#print(commaFun([]))
## Character Picture Grid
def gridFun(gridList):
nrow = len(gridList)
ncol = len(gridList[0])
for c in range(ncol):
for r in range(nrow):
print(grid[r][c], end = '')
if r == (nrow - 1):
print()
return None
grid = [['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['O', 'O', 'O', 'O', 'O', '.'],
['.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
gridFun(grid)