105k views
4 votes
Given num_rows and num_cols, print a list of all seats in a theater. rows are numbered, columns lettered, as in 1a or 3e. print a space after each seat. sample output with inputs: 2 3 1a 1b 1c 2a 2b 2c num_rows - int(input()) 2 nun_cols . Int(input()) 3 4 # Note 11 You will need to declare more variables 5 # Note 2: Place end at the end of your print statement to separate seats by spaces c1 - 1 while ci num_rows 9 c2A = 10 while c2 - 'C': 11 print('s' (c1, c2), ende'') 12 c2 - chr(ord(a) . 1) 13 cl1 14 15 print Your output 1A 1B 1C 2A 2B 2C ✓ Testing with inputs: 53 Your output 1A 1B 1C 2A 2B 2C 3A 3B 3C 4A 4B 4C 5A 5B 5C Testing with inputs: 50 Output differs. See highlights below. Special character legend Your output 1A 1B 1C 2A 2B 2C 3A 3B 3C 4A 4B 4C 5A 5B 5C Expected output Test aborted View your last submission

User Jiggy
by
8.8k points

1 Answer

4 votes

Final answer:

In order to print a list of all seats in a theater based on the given number of rows and columns, you can use nested loops to iterate through each row and column.

Step-by-step explanation:

To print a list of all seats in a theater based on the given number of rows and columns, you can use nested loops to iterate through each row and column.

Here's an example in Python:

num_rows = int (input ('Enter the number of rows: '))

num_cols = int (input ('Enter the number of columns: '))

for row in range(1, num_rows + 1):

for col in range(97, 97 + num_cols):

seat = f'{ row} { chr ( col )}'

print (seat, end=' ')

print ()

This code prompts the user for the number of rows and columns, then uses two nested loops to iterate through each row and column. It uses the ASCII code to generate the corresponding column letter. The print () statement is used to display each seat, with a space between each seat.

User Dan Albert
by
7.7k points