Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

List isn't printed fully

I'm trying to get the following code to work.

When I get to the part where the student_titlecase is supposed to print, however, only the last student id displaying.

students = []

def get_students_titlecase():
    students_titlecase = []
    for student in students:
        students_titlecase = student["name"].title()
    return students_titlecase

def print_students_titlecase():
    students_titlecase = get_students_titlecase()
    print(students_titlecase)

def add_student(name, student_id=332):
    student = {"name": name, "student_id":student_id}
    students.append(student)

student_list = get_students_titlecase()

student_entry = input("Would you like to enter a student? ('y' for yes, 'n' for no)")
student_entry = student_entry.lower()

while student_entry == 'y':
    student_name = input("Enter student name: ")
    student_id = input("Enter the student ID: ")
    add_student(student_name, student_id)
    student_entry = input("Would you like to enter another student? ('y' for yes, 'n' for no)")

print_students_titlecase()

1 Answer

Not sure as what exactly is the challenge you are trying to solve but according to what i understood:

In code:

def get_students_titlecase():
    students_titlecase = []
    for student in students:
        students_titlecase = student["name"].title()
    return students_titlecase

Maybe this is what you meant to do:

def get_students_titlecase():
    students_titlecase = []
    for student in students:
        students_titlecase.append(student["name"].title());
    return students_titlecase

Appending all the titles, rather than updating the students_titlecase;

Hope this helps.