-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords_as_a_grid.py
More file actions
104 lines (62 loc) · 2.52 KB
/
Copy pathwords_as_a_grid.py
File metadata and controls
104 lines (62 loc) · 2.52 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Takes two integers and creates a list of lists (grid) of the
specified length and width and prints the elements of each list as
comma-separated values.
"""
import random
def init():
"""Takes two integers; assigns them to the variables grid_size and
seed_value, respectively; and generates a seed based off of the
value of seed_value.
Parameters: This function does not take any parameters.
Returns: The value of variable grid_size.
Pre-condition: The inputs of grid_size and seed_value are integers.
Post-condition: The return value is an integer."""
grid_size = int(input())
seed_value = input()
random.seed(seed_value)
return grid_size
def make_grid(grid_size):
"""Utilizes the seed to randomly select 1 letter of the alphabet at a
time to create a list of lists of length and width grid_size.
Parameters: grid_size is the length and width of the list of lists
(grid).
Returns: A newly created list of lists (grid).
Pre-condition: grid_size is an integer.
Post-condition: The return value is a list of lists."""
string = "abcdefghijklmnopqrstuvwxyz"
new_grid = []
for num in range(grid_size):
counter = 0
temp_grid = []
while counter != grid_size:
temp_grid.append(string[random.randint(0, 25)])
counter += 1
new_grid.append(temp_grid)
temp_grid = []
return new_grid
def print_grid(grid):
"""Takes a list of lists and prints out the elements of each individual
list as comma-separated values.
Parameters: grid is a list of lists.
Returns: The elements of grid printed out as comma-separated values.
Pre-condition: grid is a list of lists.
Post-condition: The return value is the elements of grid printed out."""
for list in grid:
new_string = ""
for index in range(len(list)):
if index != len(list) - 1:
new_string += list[index] + ","
else:
new_string += list[index]
print(new_string)
def main():
"""Utilizes the functions init, make_grid, and print_grid in order
to print out the elements of a randomly created list of lists.
Parameters: None.
Returns: None.
Pre-condition: The functions init, make_grid, and print_grid exist
and these functions' parameters are input properly.
Post-condition: Comma-separated values printed out."""
print_grid(make_grid(init()))
main()