我需要一個二維列表來存儲關於學生及其成績的信息。創建一個二維列表
當我運行我的程序時,我只是得到一個數字列表,但我需要爲每個學生單獨列出。誰能幫我?
這是我迄今所做的:
COLS= int(input("number of students to enter "))
ROWS= int(input("number of grades per student "))
def main():
number =[]
for c in range(COLS):
student =(input("enter student ID number "))
number.append(student)
for r in range (ROWS):
grades =(input("Enter grade for module: "))
number.append(grades)
print(number)
my result is
number of students to enter 2
number of grades per student 4
enter student ID number 1234
Enter grade for module: 55
Enter grade for module: 66
Enter grade for module: 43
Enter grade for module: 33
enter student ID number 2345
Enter grade for module: 34
Enter grade for module: 56
Enter grade for module: 78
Enter grade for module: 99
['1234', '55', '66', '43', '33', '2345', '34', '56', '78', '99']
>>>
請注意,您在這裏的樓宇名單,以及一個簡單而有效的方式做到這一點是使用[list解析](HTTP:// WWW .youtube.com /手錶?ν= pShL9DCSIUw)。 – 2013-02-24 18:11:37