Question: Python: Need help with output( Student number assigns students their own number based on name and gpa) My Code: # Number of students print('How many

Python: Need help with output( Student number assigns students their own number based on name and gpa)

My Code:

# Number of students print('How many students are in the class?') student_Number = int(input())

# Store list of students who are valid student_List = []

for i in range(0, student_Number): # To store current student data student_Data = []

print('Enter the name of student:') # Name of Students student_Name = input() if len(student_Name)> 24: print('Name of student cannot exceed 24 characters.') continue print('Enter the gpa of student:') # GPA of Student student_Gpa = float(input()) if student_Gpa < 0 or student_Gpa > 4: print('GPA of student must be between 0.0 and 4.0.') continue # Adding name to current student student_Data.append(student_Name)

# Adding gpa to current student student_Data.append(student_Gpa)

# Adding students to main list student_List.append(student_Data)

# Displaying Output for valid students if len(student_List) > 0: # Header print('Number Name GPA') print('-' * 37) # To store GPA sum sum_Gpa = 0 # Displaying result for each student for student in student_List: student_Number = student_List.index(student) + 1 student_Name = student[0] student_Gpa = student[1] #Calculating sum GPA sum_Gpa += student_Gpa

print(str(student_Number) + ' ' * (10 - len(str(student_Number)) - 1) + student_Name + ' ' * (24 - len(student_Name)) + str(student_Gpa))

# Displaying Average GPA print("") print('Average GPA: ' + str(sum_Gpa/(len(student_List))))

Output should look like this:

How many students are in the class? 5 Enter the name of student: Stan Marsh Enter the gpa of student: 3.6 Enter the name of student: Kenny McCormick Enter the gpa of student: 2.3 Enter the name of student: Someone with a really long name more than 20 characters Name of student cannot exceed 24 characters. Enter the name of student: Eric Cartman Enter the gpa of student: -1.1 GPA of student must be between 0.0 and 4.0. Enter the name of student: Kyle Broflovski Enter the gpa of student: 4.0 Number Name GPA ------------------------------------- 1 Stan Marsh 3.6 2 Kenny McCormick 2.3 5 Kyle Broflovski 4.0 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!