Python正在尝试将结果打印为菜单

2024-04-20 10:55:58 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,这是我到目前为止所做的

COLS= int(input("Number of Students to enter: "))
ROWS= int(input("Number of Grades per student: "))


number =[]

for c in range(COLS):
   grades = []
   student =(input("Enter Student ID number "))
   number.append(student)
   number.append(grades)


   count = 1        
   for r in range (ROWS):
      grade = (input("Enter Grade for Module "+str(count)+ ": "))
      grades.append(grade)
      count = count + 1

print
print (number)
print
print ('Rows and Columns')

print (student) + (grades)

count = count + 1为止的一切我都很满意。但我不确定如何打印结果

    Rows and Columns
    123 88 97 66 52
    124 77 64 73 65

你知道吗^^^ 如果输入是

No of Students:2
No of grades: 4
student no.= 123
Grade 1 = 88
Grade 2= 97 
Grade 3 = 66
Grade 4 = 52

是的。 菜单的下一行是其他学生的输入。 任何帮助都将不胜感激


Tags: ofnumberforinputcountstudentrowsint
1条回答
网友
1楼 · 发布于 2024-04-20 10:55:58

您的数据结构不是最佳选择,但是…:

for i in range(len(number)):
    # if this element is an int, then following would be the list of grades.
    if isinstance(number[i],str):
        print(number[i],' '.join(map(str, number[i+1])))

相关问题 更多 >