74.3k views
0 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

User JoseV
by
8.4k points

2 Answers

7 votes

The correct code is shown below:

num_rows = int(input())

num_cols = int(input())

# Note 1: You will need to declare more variables

# Note 2: Place end=' ' at the end of your print statement to separate seats by spaces

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

for j in range(num_cols):

seat = f"{i}{c/h/r(65+j)}"

print(seat, end=" ")

print()

The above script defines a function generate_theater_seats that takes num_rows and num_cols as input and prints the list of theater seats.

The ord function is used to convert a character to its ASCII value, and chr is used to convert an ASCII value back to a character.

See text below

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())

num_cols = int(input())

# Note 1: You will need to declare more variables

# Note 2: Place end=' ' at the end of your print statement to separate seats by spaces

''' Your solution goes here '''

print()

User Gyanesh Gouraw
by
8.0k points
7 votes

Answer:

Following are the program for the above question in python:

Step-by-step explanation:

def seat(num_rows,num_cols):#function definition.

for x in range(1,num_rows+1):#first for loop.

c='A'

for y in range(1,num_cols+1): #second for loop.

print(str(x)+c,end=" ") #print the value

c=
chr(ord(c)+1) #expression to form a charater addition.

seat(int(input("enter the number of rows: ")),int(input("enter the number of columns: "))) #take the input from the user.

Output:

  • If the user inputs 2 and 3, then the output is :"1A 1B 1C 2A 2B 2C 3A 3B 3C 4A 4B 4C".

Code Explanation :

  • The above code is in python language, in which the first line is used to render a message to the user then take the inputs from the user and then pass to the function after converting into int function.
  • Then there are two loops in the function which are used to print the number of the seat.
  • The first loop is used to print the row number and the second loop is used to print the column number.
User Babu Sekaran
by
9.2k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.