232k views
0 votes
Assume you have the all_info list that is given in the Do It Now problem 1. This list includes the grades of 4 courses for 4 students. Write a code that asks a name from the user. Then it will search for that name in the list all info. Of the name exists in the list, the program will display the programming grade of that student. For example, if the user enters 'Sarah ' the program will display 90. If the user enters a name that is not in the list, such as 'Jack', the program will display an error message such as 'Sorry, but this student is not in the list'.

1 Answer

7 votes

Answer:

titles =['name', 'physics', 'chemistry', 'math', 'programming']

student_1 =['Kathy', 90, 80, 75, 100]

student_2 =['John', 65, 84, 79, 90]

student_3 =['Joe', 45, 89, 100, 10]

student_4 =['Sarah', 68, 89, 93, 90]

all_info =[titles, student_1, student_2, student_3, student_4]

student = input("Enter student's name: ")

student_list = [name[0] for name in all_info]

if student in student_list:

print(all_info[student_list.index(student)][4])

if student not in student_list:

print("Student name does not exist.")

Step-by-step explanation:

The python program prompts for user input "student" and the input is used to search and return the result of the student in the programming exam. If the name is not in the student_list, the program print an error message.

User Shan
by
4.5k points