PLEASE USE IDLE PYTHON:
Question (Arrays/Lists)
A teacher uses 2 arrays (or Lists) to keep track of his students. One is used to store student names and the other stores his grade (0-100). Write a program to create these two arrays (or lists) that are originally empty, and do the following using a menu:
1. Add a new student and his/her grade.
2. Print the name and grade of all current students, one student per line.
3. Display the number of students.
4. Print the names of students with a grade more than 90.
5. Raise the grades of all students by 5 points.
6. Exit.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== def displayMenu(): print('1. Add a new student and his/her grade.') print('2. Print the name and grade of all current students, one student per line.') print('3. Display the number of students.') print('4. Print the names of students with a grade more than 90.') print('5. Raise the grades of all students by 5 points.') print('6. Exit.') choice = input('Enter your choice: ') return choice def addStudent(names, grades): name = input('Enter student name: ') grade = int(input('Enter grade [0-100]: ')) if 0 <= grade <= 100: names.append(name) grades.append(grade) print('Student added successfully.') else: print('Sorry could not add student. Grade cannot be greater than 100 or less than 0') def main(): names = [] grades = [] while True: choice = displayMenu() if choice == '1': addStudent(names, grades) elif choice == '2': print('Printing all student names and grades:') for i in range(len(names)): print('{:<15} - Grade {}'.format(names[i], grades[i])) elif choice == '3': print('Printing all student names:') for name in names: print('{}'.format(name)) elif choice == '4': print('Printing all student names and grades >=90:') for i in range(len(names)): if grades[i] >= 90: print('{:<15} - Grade {}'.format(names[i], grades[i])) elif choice == '5': print('Raising all grades by 5 points.') for i in range(len(grades)): grades[i] = 5 + grades[i] if grades[i] <= 95 else grades[i] elif choice == '6': print('Thank You. Bye!') break else: print('Error: Invalid choice.') main()
=================================================================
Get Answers For Free
Most questions answered within 1 hours.