351,130 views
1 vote
1 vote
Create a StudentRoster application that

prompts the user for the number of students

in the class and then prompts the user for

each student's name and stores the names in

an array. After all the names have been

entered, the application should display the

title "Student Roster" and then list the names

in the array.

User Others
by
2.5k points

1 Answer

8 votes
8 votes

Answer:

Here is an example of how you can create a StudentRoster application in Python:

# Define a function to get the student names

def get_student_names(num_students):

# Initialize an empty list to store the names

names = []

# Prompt the user for each student's name and add it to the list

for i in range(num_students):

name = input(f"Enter the name of student {i+1}: ")

names.append(name)

# Return the list of names

return names

# Main function

def main():

# Prompt the user for the number of students in the class

num_students = int(input("Enter the number of students in the class: "))

# Get the names of the students

names = get_student_names(num_students)

# Display the title

print("Student Roster:")

# Display the names of the students

for name in names:

print(name)

# Run the main function

if __name__ == "__main__":

main()

This code will prompt the user for the number of students in the class, and then prompt the user for each student's name. It will store the names in a list, and then display the title "Student Roster" followed by the names of the students.

Step-by-step explanation:

User Alex Yaroshevich
by
3.1k points