0
# This program records the names of 12 students in a list
# named students.
NUM_STUDENTS = 12
def main():
# Create a list to hold the names of students.
students = [0] * NUM_STUDENTS
# Create a variable to hold an index
index = 0
print('Enter the names of 12 students.')
# Add student names to the list.
while index < NUM_STUDENTS:
# Get the name of a student from the user.
students[index] = input('Enter the name of a student: ')
index += 1
# Append a name to the student list.
students.append(students)
ソート時にエラーが発生しましたか?これをどうやって解決するのですか?ライン24は、メイン students.sort()TypeError例外で:unorderableタイプ:students.append(students)
:リスト()< STR()私は次のコードの投げとエラーがあります。
# Sort the list of name alphabetically.
students.sort()
print('Alphabetically sorted list of names:', students)
# Reverse the list of names
students.reverse()
print('Reverse sorted list of name:', students)
この行が末尾にある必要はありません students.append(students) –