def calc_average_enrolment(records): #calculate total and average total = 0 for i in range(records): total += i[2] average = total / len(records) print('Total ' + str(total)) print('Average ' + str(average)) print('Done.\n\n') def print_all(records): #print all records template = '{0:<10} {1:<20} {2:<10}' print(template.format('CID','Name','Enrolment')) print('-' * 50) for i in range(records): print(template.format(i[0],i[1],i[2])) print('Done.\n\n') def search_by_courseid(records): #query record by course id template = '{0:<10} {1:<20} {2:<10}' count = 0 id = input('Enter course ID: ') for i in records: if id == i[0]: print(template.format(i[0],i[1],i[2])) break else: count += 1 if count >= len(records): print('No record found for course id ' + id) print('Done.\n\n') def getdata(): #course_list contains: course_id, course name, number of enrolled students course_list = [] course_list.append(['comp001','Fundamentals',135]) course_list.append(['comp002','Intro Database',30]) course_list.append(['comp003','Web programming',24]) return course_list def main(): data = getdata() print_all(data) calc_average_enrolment(data) search_by_courseid(data) main()
下の図になるようにコードを書いたつもりですがエラーが出ています????????
どなたかコードチェックお願いしていいですか
よろしくおねがいします。
回答1件
あなたの回答
tips
プレビュー