Answer:
The solution code is written in Python:
- alphabets = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
-
- user_input = input("Enter row and columns: ")
- myArr = user_input.split(" ")
- num_rows = int(myArr[0])
- num_cols = int(myArr[1])
-
- seats = []
-
- for i in range(num_rows):
- row = []
- for j in range(num_cols):
- row.append(alphabets[j])
-
- seats.append(row)
-
- output = ""
-
- for i in range(len(seats)):
- for j in range(len(seats[i])):
- output += str(i + 1) + seats[i][j] + " "
-
- print(output)
Step-by-step explanation:
Firstly, we define a short alphabets list from A - J (Line 1).
Next, we prompt user to input row and columns (Line 3). Since the input is a string (e.g. "2 3"), we need to use split() method to separate the individual row and column number as individual element in a list (Line 4). We assign the first element (row number) to variable num_rows and second element (column number) to variable num_cols.
Next, we generate the seats list by using a two-layers for-loop (Line 10 -15). After the seat list is ready, we use another two-layers for-loop to generate output string as required by the question (Line 19-21).
At last, we print the output (Line 23). A sample input of 2 3 will generate the output as follows:
1A 1B 1C 2A 2B 2C