python create a checkerboard generator, which takes as inputs n and 2 elements and generates an n x n checkerboard with the two elements as alternating squares. For example, if n = 3 and the elements are a and b, the checkerboard would be: [ ['a', 'b', 'a'], ['b', 'a', 'b'], ['a', 'b', 'a'] ] Treat all inputs as strings. The first element should go in the upper left of the checkerboard. Example Execution #1 What is the length of the sides of the checkerboard? LENGTH> 3 What are the strings with which to pattern it? FIRST> a SECOND> b A checkerboard with side length 3, first string is a, and second string is b is: OUTPUT ['a', 'b', 'a'] OUTPUT ['b', 'a', 'b'] OUTPUT ['a', 'b', 'a'] And the 2D array representation is: OUTPUT [['a', 'b', 'a'], ['b', 'a', 'b'], ['a', 'b', 'a']] Example Execution #2 What is the length of the sides of the checkerboard? LENGTH> 4 What are the strings with which to pattern it? FIRST> 67 SECOND> HA A checkerboard with side length 4, first string is 67, and second string is HA is: OUTPUT ['67', 'HA', '67', 'HA'] OUTPUT ['HA', '67', 'HA', '67'] OUTPUT ['67', 'HA', '67', 'HA'] OUTPUT ['HA', '67', 'HA', '67'] And the 2D array representation is: OUTPUT [['67', 'HA', '67', 'HA'], ['HA', '67', 'HA', '67'], ['67', 'HA', '67', 'HA'], ['HA', '67', 'HA', '67']]
python
create a checkerboard generator, which takes as inputs n and 2 elements and generates an n x n checkerboard with the two elements as alternating squares. For example, if n = 3 and the elements are a and b, the checkerboard would be:
[
['a', 'b', 'a'],
['b', 'a', 'b'],
['a', 'b', 'a']
]
Treat all inputs as strings. The first element should go in the upper left of the checkerboard.
Example Execution #1
What is the length of the sides of the checkerboard?
LENGTH> 3
What are the strings with which to pattern it?
FIRST> a
SECOND> b
A checkerboard with side length 3, first string is a, and second string is b is:
OUTPUT ['a', 'b', 'a']
OUTPUT ['b', 'a', 'b']
OUTPUT ['a', 'b', 'a']
And the 2D array representation is:
OUTPUT [['a', 'b', 'a'], ['b', 'a', 'b'], ['a', 'b', 'a']]
Example Execution #2
What is the length of the sides of the checkerboard?
LENGTH> 4
What are the strings with which to pattern it?
FIRST> 67
SECOND> HA
A checkerboard with side length 4, first string is 67, and second string is HA is:
OUTPUT ['67', 'HA', '67', 'HA']
OUTPUT ['HA', '67', 'HA', '67']
OUTPUT ['67', 'HA', '67', 'HA']
OUTPUT ['HA', '67', 'HA', '67']
And the 2D array representation is:
OUTPUT [['67', 'HA', '67', 'HA'], ['HA', '67', 'HA', '67'], ['67', 'HA', '67', 'HA'], ['HA', '67', 'HA', '67']]
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images