Lists | SoloLearn: Learn to code for FREE!

0

Lists

The seats in your ticketing program are stored in a 2D list. Each seat is assigned a letter code. Complete the program to take the seat row and column as input and output the corresponding code from the list (row and column indices start from 0). Sample Input 3 2 Sample Output k Note, that you need to convert the input() to int, in order to use it as an index.

4/11/2021 6:06:58 AM

Veena Tirmal

9 Answers

New Answer

-1

So, you have to take two inputs. First input = row Second input = column Then, use int() on both input to convert them to integers. Then you can get the output. Output = list [row] [column] This is the logic you should follow. row = int(input()) column = int(input()) print(seats[row][column])

+2

Chandan Roy wrote, "Well, you can find this here. Courses[Python for beginners][Lists][29.2] Trying to find it in Python core will give an index error " Response: Ok. It is "Where's my Seat" in the Python for Beginners in the Lists section. It is a Pro-only practice question so I didn't do that yet. Veena wrote, "This is from python core" which is why I searched the Python Core course earlier.

+1

Can you share your attempt? Is that from Python?

+1

It's very simple, just try this: seats = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'] ] row = int(input()) column = int(input()) print(seats[row][column])

0

seats = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'] ] When I'm starting to solve, I'm given this Josh Greig CHANDAN ROY

0

Veena Tirmal It's okay. Don't get discouraged. Try to understand the problem. Indexing is a way to access the elements from a list. As it's not good to post complete solution here, I have sent solution in DM with explanation.

0

I completed the Python Core course and can't find that question but I have an attempt below. One thing that makes little sense to me about that question is the 3, 2 inputs leading to 'k' and how they also say the indexes start at 0. The 3 is understandable but the 'k' is at index 1 from its containing list which means that if 2 corresponds with that index, it must be 1-based instead of 0-based. I used that assumption in the code below: seats = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'] ] n = int(input()) m = int(input()) print(seats[n][m - 1]) The above code will print k for inputs: 3 2 I'm just not sure it is right given the apparent contradiction in requirements.

0

Well, you can find this here. Courses[Python for beginners][Lists][29.2] Trying to find it in Python core will give an index error

-1

This is from python core, I tried different concepts maybe I'm too weak at this Josh Greig CHANDAN ROY