如何创建一个调用aand的功能以打印每个学生的姓名和课程

时间:2019-03-07 21:44:27

标签: python

这是我到目前为止所拥有的

from CSE_324_course import Course
from CSE_324_skeleton_student import Student

math = Course("Algebra I")
language = Course("Spanish I")
science = Course("Earth Science")
history = Course("U.S. History I")
phys_ed = Course("Physical Education I")
speaking = Course("Speech I")
art = Course("Art I")

test_student = Student("Jill", "Sample")

test_student.add_course(math)
test_student.add_course(language)
 test_student.add_course(science)
test_student.add_course(history)

test_student2 = Student("Bill", "Sample")

test_student2.add_course(math)
test_student2.add_course(phys_ed)
test_student2.add_course(science)
test_student2.add_course(history)

test_student3 = Student("Kim", "Sample")

test_student3.add_course(language)
test_student3.add_course(speaking)
test_student3.add_course(science)
test_student3.add_course(art)

student_list=[test_student,test_student2,test_student3]

for (test_student,test_student2,test_student3 : get_course)
if (test_student().equals(search))
 System.out.println(teststudnetgetCourse());


#Each iteration should:
    #get,concatenate, and print the first and last name of the student
    #print all courses for that student
    #print a blank line between students

'''对于这部分,您可能需要查看其他框架代码以:         -了解如何从列表中获取商品         -查看该文件中是否有代码(如函数),您可以在该文件中调用         -验证运行此文件是否可以从该文件获得正确的输出信息     另外,请查看从列表f

提取项目的语法

2页代码     课程导入课程

class Student:

student_id = 0

def __init__(self, first_name, last_name):
    self.first_name = first_name
    self.last_name = last_name
    self.courses = []
    self.student_id = Student.student_id
    Student.student_id += 1

def __str__(self):


    # TODO You will need to use a variable in the loop, so you must intialize it here,
    # that variable will need to be initalized to get items listed in the first def _init_ section
    # TODO add a loop that will go through the course list
        # TODO Add code here to create a string representation of a student,
        # including first and last name and all courses that student is taking
    return "complete this return statement based on your in loop variable"

def get_first_name(self):
    return self.first_name

def get_last_name(self):
    return self.last_name

def get_student_id(self):
    return self.student_id

def add_course(self, new_course):
    # TODO add code to append new_course to self.courses
    print "Course not yet added, implementation needed."

第3页     课程:

    def __init__(self, course_name):
        self.course_name = course_name

    def __str__(self):
        return self.course_name

1 个答案:

答案 0 :(得分:0)

我认为您正在寻求改变

for (test_student,test_student2,test_student3 : get_course)
    if (test_student().equals(search))
        System.out.println(teststudnetgetCourse());

(您未正确缩进)以:

for student in student_list:
    print("{} {}".format(student.first_name, student.last_name))
    for course in student.courses:
        print(course) # This won't work because "2 page of code Course import Course" needs to be finished
    print("\n") # blank line between students