r/pythonhelp • u/Maleficent-Break1738 • Dec 09 '22
Problem with understanding lists/arrays and creating a list from another list...
Hi this semester I enrolled in a computer science class and I am confused on this code. I was assigned to create a code that can create a 3x3 multidimensional list that takes the input of elements from the user. I then need to store all the "A" grades in a new list. I attempted to do so and keep getting an error stating "TypeError: '<=' not supported between instances of 'list' and 'int'. Just need help understanding what I am doing wrong. Thanks in advance. Here's my code for reference
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))
matrix = []
print("Enter the entries rowwise:")
for i in range(R): # A for loop for row entries
a =[]
for j in range(C): # A for loop for column entries
a.append(int(input()))
matrix.append(a)
print (matrix)
A_grades=[]
B_Grades=[]
C_Grades=[]
def grades_a(matrix):
for x in matrix:
if x <= 100 and x >= 90:
A_grades.append()
print(A_grades)
grades_a(matrix)
1
u/Goobyalus Dec 09 '22
In the future, please format your code properly for Reddit. This is my guess as to how your code is formatted:
Is that right?
When you run your code and pring out the matrix, you see something like this, right?
The matrix is a list of lists. So
matrix[0]is the sublist[1, 2, 3], andmatrix[0][1]is like[1, 2, 3]indexed at1, so2.Does that help you understand the error?:
Also have alook at