diff --git a/Week2_1.py b/Week2_1.py new file mode 100644 index 0000000..0fa4db9 --- /dev/null +++ b/Week2_1.py @@ -0,0 +1,188 @@ +""" +Question1: Student Grades Processing +You need to write a Python program to process a student's grades. The program needs to perform the following functions: + +Store information and notes for 10 students using a dictionary. Let each student have their name, surname and grades (Midterm, Final and Oral grades). For example: + +students = { + "Ahmet Yılmaz": [85, 90, 78], #Midterm: 85, Final: 90, Oral: 78 + 'Mehmet Demir': [92, 88, 76], #Midterm: 92, Final: 88, Oral: 76 + "Ayşe Kaya": [78, 89, 95], #Midterm: 78, Final: 89, Oral: 95 + "Zeynep Çelik": [65, 70, 80], #Midterm: 65, Final: 70, Oral: 80 + 'Ali Kara': [50, 60, 55], #Midterm: 50, Final: 60, Oral: 55 + 'Fatma Yıldız': [88, 85, 90], #Midterm: 88, Final: 85, Oral.: 90 + 'Murat Aydın': [72, 68, 74], #Midterm: 72, Final: 68, Oral: 74 + 'Elif Aksoy': [95, 98, 88], #Midterm: 95, Final: 90, Oral: 88 + "Hakan Öztürk": [45, 50, 55], #Midterm: 45, Final: 50, Oral: 55 + "Canan Taş": [80, 75, 82] #Midterm: 80, Final: 75, Oral: 82 +} + +1-Calculate each student's GPA and add it to the dictionary. + +2-Find the student with the highest GPA and print it on the screen. + +3- Separate each student's name from their surname and store them in a separate tuple and add them to a list. + +4-Sort the names in alphabetical order and print the sorted list on the screen. + +5-Keep students with a GPA below 70 in a cluster (set). +""" +import os + +# Main program +if __name__ == "__main__": + students = dict() + grade_rates = [20, 60, 20] + incorrectly_entered = False + exit_confirmation = True + while exit_confirmation : + os.system("clear" if os.name == "posix" else "cls") + main_menu = [ + "_____________________________________________________", + " Student Information System ", + "_____________________________________________________", + " (1) Student Adding Procedures.\n", + " (2) Student with the Highest Grade Point Average.\n", + " (3) Alphabetical Student List.\n", + " (4) List of students with a general average below 70.\n", + f" (s) Change the average calculation rates.(Midterm: %{(grade_rates[0]/sum(grade_rates) * 100):.2f} Final: %{(grade_rates[1]/sum(grade_rates) * 100):.2f} Oral: %{(grade_rates[2]/sum(grade_rates) * 100):.2f})\n", + " (q) You can exit the program by pressing.\n\n" + ] + + for i in main_menu: + print(i) + + if incorrectly_entered: + print('\t'.expandtabs(5), "You have entered incorrectly. Please check the menu and make your selection again!") + incorrectly_entered = False + + print('\t'.expandtabs(5), "Please select the action you wish to perform:", end=" ") + select_menu = input() + + if select_menu in ["q", "Q"]: + exit_confirmation = False + elif select_menu == "1": + exit_student_menu = True + while exit_student_menu: + os.system("clear" if os.name == "posix" else "cls") + print(f"Name Surename: [Midterm: %{(grade_rates[0]/sum(grade_rates) * 100):.2f} Final: %{(grade_rates[1]/sum(grade_rates) * 100):.2f} Oral: %{(grade_rates[2]/sum(grade_rates) * 100):.2f}, GAB]\n", + "___________________________________________") + for student,grade in students.items(): + print(student," : ",grade) + main_menu = main_menu = [ + "_____________________________________________________", + " Student Adding Procedures. ", + "_____________________________________________________", + " (1) Adding a Student.\n", + " (2) Student Correction.\n", + " (3) Student Deletion.\n", + " (4) Add standard student list.\n", + " (m) To return to the main menu.\n\n" + ] + for i in main_menu: + print(i) + + if incorrectly_entered: + print('\t'.expandtabs(5), "You have entered incorrectly. Please check the menu and make your selection again!") + incorrectly_entered = False + + print('\t'.expandtabs(5), "Please select the action you wish to perform:", end=" ") + select_menu = input() + if select_menu in ["m", "M"]: + exit_student_menu = False + elif select_menu == "1": + new_student_name = input("Please enter the student's name: ") + new_student_surname = input("Please enter the student's surname: ") + if new_student_name+" "+ new_student_surname in students.keys(): + print("This student already exists.") + input("Press enter to continue...") + else: + new_student_midterm = int(input("Please enter the student's midterm grade: ")) + new_student_final = int(input("Please enter the student's final grade: ")) + new_student_oral = int(input("Please enter the student's oral grade: ")) + new_student_gab = round((new_student_midterm * grade_rates[0] + new_student_final * grade_rates[1] + new_student_oral * grade_rates[2]) / sum(grade_rates) , 2) + students[new_student_name+" "+ new_student_surname] =[new_student_midterm, new_student_final, new_student_oral, new_student_gab] + print("Student added successfully.") + elif select_menu == "2": + edit_student_name = input("Please enter the student's name and surename you want to edit: ") + if edit_student_name in students.keys(): + edit_student_midterm = int(input("Please enter the student's midterm grade: ")) + edit_student_final = int(input("Please enter the student's final grade: ")) + edit_student_oral = int(input("Please enter the student's oral grade: ")) + edit_student_gab = round((edit_student_midterm * grade_rates[0] + edit_student_final * grade_rates[1] + edit_student_oral * grade_rates[2]) / sum(grade_rates) , 2) + students[edit_student_name] = [edit_student_midterm, edit_student_final, edit_student_oral, edit_student_gab] + print("Student edited successfully.") + else: + print("Student not found.") + input("Press enter to continue...") + elif select_menu == "3": + delete_student_name = input("Please enter the student's name and surename you want to delete: ") + if delete_student_name in students.keys(): + if True if input("Are you sure you want to delete the student? (Y/N): ") in ["y","Y"] else False: + del students[delete_student_name] + print("Student deleted successfully.") + else: + print("Student deletion canceled.") + input("Press enter to continue...") + else: + print("Student not found.") + input("Press enter to continue...") + elif select_menu == "4": + confirmation = True if input("Are you sure you want to add the standard student list? (Y/N): ") in ["y","Y"] else False + if confirmation: + students = { + "Ahmet Yılmaz": [85, 90, 78,round((85 * grade_rates[0] + 90 * grade_rates[1] + 78 * grade_rates[2]) / sum(grade_rates) , 2)], + 'Mehmet Demir': [92, 88, 76,round((92 * grade_rates[0] + 88 * grade_rates[1] + 76 * grade_rates[2]) / sum(grade_rates) , 2)], + "Ayşe Kaya": [78, 89, 95,round((78 * grade_rates[0] + 89 * grade_rates[1] + 95 * grade_rates[2]) / sum(grade_rates) , 2)], + "Zeynep Çelik": [65, 70, 80,round((65 * grade_rates[0] + 70 * grade_rates[1] + 80 * grade_rates[2]) / sum(grade_rates) , 2)], + "Ali Kara": [50, 60, 55,round((50 * grade_rates[0] + 60 * grade_rates[1] + 55 * grade_rates[2]) / sum(grade_rates) , 2)], + "Fatma Yıldız": [88, 85, 90,round((88 * grade_rates[0] + 85 * grade_rates[1] + 90 * grade_rates[2]) / sum(grade_rates) , 2)], + "Murat Aydın": [72, 68, 74,round((72 * grade_rates[0] + 68 * grade_rates[1] + 74 * grade_rates[2]) / sum(grade_rates) , 2)], + "Elif Aksoy": [95, 98, 88,round((95 * grade_rates[0] + 98 * grade_rates[1] + 88 * grade_rates[2]) / sum(grade_rates) , 2)], + "Hakan Öztürk": [45, 50, 55,round((45 * grade_rates[0] + 50 * grade_rates[1] + 55 * grade_rates[2]) / sum(grade_rates) , 2)], + "Canan Taş": [80, 75, 82,round((80 * grade_rates[0] + 75 * grade_rates[1] + 82 * grade_rates[2]) / sum(grade_rates) , 2)] + } + + else: + incorrectly_entered = True + elif select_menu == "2": + max_student = list() + max_grade = 0 + for student,grade in students.items(): + if len(max_student) == 0: + max_student.append(student) + max_grade = grade[3] + elif grade[3] == max_grade: + max_student.append(student) + elif grade[3] > max_grade: + max_student = [student] + max_grade = grade[3] + print(max_student," Max Grade: ",max_grade) + input("Press enter to continue...") + elif select_menu == "3": + alfabetic_students = list() + unsorted_students = list() + for student in students.keys(): + student_tuple = tuple(student.split(" ")) + unsorted_students.append(student_tuple) + alfabetic_students = sorted(unsorted_students, key=lambda x: x[0]) + for student in alfabetic_students: + print(student) + input("Press enter to continue...") + elif select_menu == "4": + less_gab_students = set() + for student,grade in students.items(): + if grade[3] < 70: + less_gab_students.add(student) + for student in less_gab_students: + print(student) + input("Press enter to continue...") + elif select_menu in ["s", "S"]: + print("The value you enter for each grade will be taken as a multiplier. For example, if you enter the same value for all three, all grades will be evaluated equally. \n Please enter the new grade rates.") + grade_rates[0] = float(input("Please enter the new midterm grade rate: ")) + grade_rates[1] = float(input("Please enter the new final grade rate: ")) + grade_rates[2] = float(input("Please enter the new homework grade rate: ")) + for student,grade in students.items(): + students[student][3] = round((grade[0] * grade_rates[0] + grade[1] * grade_rates[1] + grade[2] * grade_rates[2]) / sum(grade_rates) , 2) + else: + incorrectly_entered = True diff --git a/Week2_2.py b/Week2_2.py new file mode 100644 index 0000000..ee4b428 --- /dev/null +++ b/Week2_2.py @@ -0,0 +1,247 @@ +""" +Question 2: Film Library Management System Project +Project Description: This project aims to create an application that will help the user manage their movie collection. Users can add, edit, delete movies and view their collection. + +Data Structures Used: Dictionaries (to store movies and related information), lists (to display movie collection) + +Basic Functions: + +1-Create a movie data by taking information such as movie name, director, release year and genre from the user and store it in a dictionary. + +2-Give the user the option to edit or delete a movie. (For this, a suitable function must be written for whatever data they want to change about the movie.) + +3-Allow the user to view their collection. List all movies or filter by criteria such as genre or year of release. + +4-Save the movie data in a file and restore this data when you start the program. +""" +import os +import json + +def save_file(file_path, data): + try: + with open(file_path, 'w', encoding='utf-8') as file: + json.dump(data, file, ensure_ascii=False, indent=4) + # print(f"Data was successfully written to file: {file_path}") + except Exception as e: + print(f"Error: Data could not be written to file. Details: {e}") + +def load_file(file_path): + """ + Reads a list from a file in JSON format. + """ + if not os.path.exists(file_path): + save_file(file_path, []) + return [] + try: + with open(file_path, 'r', encoding='utf-8') as file: + return json.load(file) + except json.JSONDecodeError: + print("Error: JSON format is invalid.") + return [] + except Exception as e: + print(f"Error: File could not be read. Details: {e}") + return [] + +# Main program +if __name__ == "__main__": + movies_file = "movies.txt" + movie_keys_file = "movie_keys.txt" + # if not os.path.exists(movies_file): + # save_file(movies_file, []) + # if not os.path.exists(movie_keys_file): + # save_file(movie_keys_file, []) + movies= load_file(movies_file) + movie_keys = load_file(movie_keys_file) + incorrectly_entered = False + exit_confirmation = True + while exit_confirmation: + os.system("clear" if os.name == "posix" else "cls") + main_menu = main_menu = [ + "_____________________________________________________", + " Film Library Management ", + "_____________________________________________________\n", + " (1) Movie Adding Procedures.\n", + " (2) Movie List.\n\n", + " (q) You can exit the program by pressing.\n\n" + ] + + for i in main_menu: + print(i) + + if incorrectly_entered: + print('\t'.expandtabs(5), "You have entered incorrectly. Please check the menu and make your selection again!") + incorrectly_entered = False + + print('\t'.expandtabs(5), "Please select the action you wish to perform:", end=" ") + select_menu = input() + + if select_menu in ["q", "Q"]: + exit_confirmation = False + elif select_menu == "1": + exit_submenu1 = True + while exit_submenu1: + os.system("clear" if os.name == "posix" else "cls") + movie_id = 1 + for movie in movies: + print(movie_id,"\t".expandtabs(3), end="") + print(movie) + movie_id += 1 + main_menu = [ + "_____________________________________________________", + " Movie Adding Procedures. ", + "_____________________________________________________\n", + " (1) Adding a Movie.", + " (2) Movie Correction.", + " (3) Movie Deletion.", + " (4) Edit movie info fields.\n", + " (q) To return to the main menu.\n" + ] + for i in main_menu: + print(i) + + if incorrectly_entered: + print('\t'.expandtabs(5), "You have entered incorrectly. Please check the menu and make your selection again!") + incorrectly_entered = False + + print('\t'.expandtabs(5), "Please select the action you wish to perform:", end=" ") + select_menu = input() + if select_menu in ["q", "Q"]: + exit_submenu1 = False + elif select_menu == "1": + movie = {} + for key in movie_keys: + movie[key] = input(f"Please enter the movie {key}: ") + if movie not in movies: + movies.append(movie) + save_file(movies_file, movies) + print("Movie added successfully.") + input("Press enter to continue...") + else: + print("This movie already exists.") + input("Press enter to continue...") + elif select_menu == "2": + edit_movie_id = input("Please enter the movie ID you want to edit: ") + if edit_movie_id.isdigit(): + edit_movie_id = int(edit_movie_id) + else: + edit_movie_id = -1 + if edit_movie_id in range(1, len(movies)+1): + movie = movies[edit_movie_id-1] + for key in movie_keys: + movie[key] = input(f"Please enter the movie {key}: ") + movies[edit_movie_id-1] = movie + save_file(movies_file, movies) + elif select_menu == "3": + delete_movie_id = input("Please enter the movie ID you want to delete: ") + if delete_movie_id.isdigit(): + delete_movie_id = int(delete_movie_id) + else: + delete_movie_id = -1 + if delete_movie_id in range(1, len(movies)+1): + if True if input("Are you sure you want to delete the movie? (Y/N): ") in ["y","Y"] else False: + del movies[delete_movie_id-1] + save_file(movies_file, movies) + print("Movie deleted successfully.") + else: + print("Movie deletion canceled.") + input("Press enter to continue...") + elif select_menu == "4": + exit_submenu2 = True + while exit_submenu2: + os.system("clear" if os.name == "posix" else "cls") + index_key = 1 + print('\t'.expandtabs(5),"ID-",'\t'.expandtabs(1), "Key") + for key in movie_keys: + print("\t".expandtabs(5),index_key,"- ","\t".expandtabs(1),key) + index_key += 1 + main_menu = [ + "_____________________________________________________", + " Student Adding Procedures. ", + "_____________________________________________________\n", + " (1) Adding a Key.\n", + " (2) Key Correction.\n", + " (3) Key Deletion.\n", + " (q) To return to the upper menu.\n\n" + ] + for i in main_menu: + print(i) + + if incorrectly_entered: + print('\t'.expandtabs(5), "You have entered incorrectly. Please check the menu and make your selection again!") + incorrectly_entered = False + + print('\t'.expandtabs(5), "Please select the action you wish to perform:", end=" ") + select_menu = input() + if select_menu in ["q", "Q"]: + exit_submenu2 = False + elif select_menu == "1": + new_key = input("Please enter the new key: ") + if new_key not in movie_keys: + movie_keys.append(new_key) + save_file(movie_keys_file, movie_keys) + print("Key added successfully.") + input("Press enter to continue...") + else: + print("This key already exists.") + input("Press enter to continue...") + elif select_menu == "2": + select_key = input("Please enter the key ID you want to edit: ") + if select_key.isdigit(): + select_key = int(select_key) + else: + select_key = -1 + if select_key in range(1, len(movie_keys)+1): + new_key = input("Please enter the new key: ") + if new_key not in movie_keys: + movie_keys[select_key-1] = new_key + save_file(movie_keys_file, movie_keys) + print("Key edited successfully.") + input("Press enter to continue...") + else: + print("This key already exists.") + input("Press enter to continue...") + else: + print("Invalid key ID.") + input("Press enter to continue...") + elif select_menu == "3": + select_key = input("Please enter the key ID you want to delete: ") + if select_key.isdigit(): + select_key = int(select_key) + else: + select_key = -1 + if select_key in range(1, len(movie_keys)+1): + if True if input("Are you sure you want to delete the key? (Y/N): ") in ["y","Y"] else False: + del_keys = movie_keys[select_key-1] + del movie_keys[select_key-1] + save_file(movie_keys_file, movie_keys) + for movie in movies: + del movie[del_keys] + save_file(movies_file, movies) + print("Key deleted successfully.") + input("Press enter to continue...") + else: + print("Key deletion canceled.") + input("Press enter to continue...") + else: + print("Invalid key ID.") + input("Press enter to continue...") + else: + incorrectly_entered = True + else: + incorrectly_entered = True + elif select_menu == "2": + print("Movie ID".center(16, " "), end="") + for key in movie_keys: + print(key.center(35, " "), end="") + print() + print("----------".center((len(movie_keys)*35+16), "-")) + movie_id = 1 + for movie in movies: + print(str(movie_id).center(16, " "), end="") + for key in movie_keys: + print(movie[key].center(35, " "), end="") + print() + movie_id += 1 + input("\n\n\nPress enter to continue...") + else: + incorrectly_entered = True diff --git a/Week2_3.py b/Week2_3.py new file mode 100644 index 0000000..d64524d --- /dev/null +++ b/Week2_3.py @@ -0,0 +1,178 @@ +""" +Question 3: Customer Management System +Project Description: This project involves you creating a customer management system that you can use to manage your customers and perform basic transactions. This system will have basic functions such as storing customer information, adding new customers, updating customer information, deleting customers and viewing the customer list. Here are the basic steps of the project: + +1-Use a dictionary structure to store customer information. Assign a unique customer identification (ID) for each customer and associate customer information with this ID. You can use a dictionary containing information such as name, surname, e-mail, phone number for each customer. + +2-Provide a menu where the user can choose the following actions: + +Add new customers +Updating customer information +Delete customer +List all customers +Check out +3-Perform the relevant action according to the user's choice. For example, when adding a new customer, get the required information from the user and add a new customer to the dictionary. + +4-When updating customer information, view the current information using the customer ID and save the updated information. + +5-In the customer deletion process, get the customer ID from the user and delete this customer from the dictionary. + +6-In the process of listing all customers, view the list of existing customers. + +7-Repeat the process until the user logs out. +""" +import os +import json + +def save_file(file_path, data): + try: + with open(file_path, 'w', encoding='utf-8') as file: + json.dump(data, file, ensure_ascii=False, indent=4) + # print(f"Data was successfully written to file: {file_path}") + except Exception as e: + print(f"Error: Data could not be written to file. Details: {e}") +def load_file(file_path): + """ + Reads a list from a file in JSON format. + """ + if not os.path.exists(file_path): + save_file(file_path, []) + return [] + try: + with open(file_path, 'r', encoding='utf-8') as file: + return json.load(file) + except json.JSONDecodeError: + print("Error: JSON format is invalid.") + return [] + except Exception as e: + print(f"Error: File could not be read. Details: {e}") + return [] + + +def add_customer(customers, customers_file): + """ + Adds a new customer to the customer list. + """ + customer_id = max(customer["id"] for customer in customers) + 1 if customers else 1 + name = input("Enter customer name: ") + surname = input("Enter customer surname: ") + email = input("Enter customer email: ") + phone = input("Enter customer phone number: ") + address = input("Enter customer address: ") + customers.append({"id": customer_id, "name": name, "surname": surname, "email": email, "phone": phone, "address": address}) + save_file(customers_file, customers) + print(f"Customer {name} {surname} added successfully.") + return True + +def update_customer(customers, customer_id, customers_file): + """ + Updates the information of an existing customer. + """ + for customer in customers: + if customer["id"] == customer_id: + customer["name"] = input("Enter new name: ") + customer["surname"] = input("Enter new surname: ") + customer["email"] = input("Enter new email: ") + customer["phone"] = input("Enter new phone number: ") + customer["address"] = input("Enter new address: ") + save_file(customers_file, customers) + print(f"Customer {customer['name']} {customer['surname']} updated successfully.") + return True + return False + +def delete_customer(customers, customer_id, customers_file): + """ + Deletes a customer from the customer list. + """ + for customer in customers: + if customer["id"] == customer_id: + customers.remove(customer) + print(f"Customer {customer['name']} {customer['surname']} deleted successfully.") + save_file(customers_file, customers) + return True + return False + +def list_customers(customers): + """ + Lists all customers in the customer list. + """ + if not customers: + print("No customers found.") + else: + print("----------".center(130, "-")) + print("ID".center(10, " "), "Name".center(20, " "), "Surname".center(20, " "), "Email".center(30, " "), "Phone".center(15, " "), "Address".center(35, " ")) + print("----------".center(130, "-")) + for customer in customers: + print(str(customer['id']).center(10, " "),customer['name'].center(20," "),customer['surname'].center(20, " "),customer['email'].center(30, " "),customer['phone'].center(15," "),customer['address'].center(30, " ")) + print("----------".center(130, "-")) + print() + +# Main Program +if __name__ == "__main__": + customers_file = "customers.txt" + customers = load_file(customers_file) + incorrectly_entered = False + exit_confirmation = True + while exit_confirmation: + os.system("clear") if os.name == "posix" else os.system("cls") + list_customers(customers) + + main_menu = ["╔════════════════════════════════════════════════════════════╗ ", + "║ WELCOME TO ║ ", + "║ The Customer Management System ║ ", + "╠════════════════════════════════════════════════════════════╣ ", + "║ (1) Add new customers ║ ", + "║ (2) Update customer information ║ ", + "║ (3) Delete customer ║ ", + "║ (4) List all customers ║ ", + "║ ║ ", + "╠════════════════════════════════════════════════════════════╣ ", + "║ (Q) Quit // Check Out ║ ", + "╚════════════════════════════════════════════════════════════╝ " + ] + for i in main_menu: + print(i) + if incorrectly_entered: + print('\t'.expandtabs(2), "You have entered incorrectly. Please check the menu and make your selection again!") + incorrectly_entered = False + + print('\t'.expandtabs(2), "Please select the action you wish to perform:", end=" ") + select_menu = input() + + if select_menu in ["q", "Q"]: + exit_confirmation = False + elif select_menu == "1": + add_customer(customers, customers_file) + elif select_menu == "2": + os.system("clear") if os.name == "posix" else os.system("cls") + list_customers(customers) + update_customer_id = input("Enter customer ID to update: ") + if update_customer_id.isdigit(): + update_customer_id = int(update_customer_id) + if update_customer(customers, update_customer_id, customers_file): + input("Press Enter to continue...") + else: + print("Customer not found.") + input("Press Enter to continue...") + else: + print("Invalid customer ID. Please enter a valid ID.") + input("Press Enter to continue...") + elif select_menu == "3": + os.system("clear") if os.name == "posix" else os.system("cls") + list_customers(customers) + delete_customer_id = input("Enter customer ID to delete: ") + if delete_customer_id.isdigit(): + delete_customer_id = int(delete_customer_id) + if delete_customer(customers, delete_customer_id, customers_file): + input("Press Enter to continue...") + else: + print("Invalid customer ID. Please enter a valid ID.") + input("Press Enter to continue...") + else: + print("Invalid customer ID. Please enter a valid ID.") + input("Press Enter to continue...") + elif select_menu == "4": + list_customers(customers) + input("Press Enter to continue...") + else: + incorrectly_entered = True diff --git a/Week2_HackerRank.py b/Week2_HackerRank.py new file mode 100644 index 0000000..254963d --- /dev/null +++ b/Week2_HackerRank.py @@ -0,0 +1,44 @@ +# https://www.hackerrank.com/challenges/list-comprehensions/problem +if __name__ == '__main__': + x = int(input()) + y = int(input()) + z = int(input()) + n = int(input()) + comprehensions_list = list() + for i in range(x+1): + for j in range(y+1): + for k in range(z+1): + if(i + j + k) != n : + comprehensions_list.append([i,j,k]) + print(comprehensions_list) + +"""---------------------------------------------------""" +# https://www.hackerrank.com/challenges/python-tuples/problem + +if __name__ == '__main__': + n = int(input()) + integer_list = map(int, input().split()) + tuple_list= tuple(integer_list) + print(hash(tuple_list)) + +"""---------------------------------------------------""" +# https://www.hackerrank.com/challenges/nested-list/problem +if __name__ == '__main__': + students = list() + for _ in range(int(input())): + name = input() + score = float(input()) + students.append((name, score)) + + students_sorted = sorted(students, key=lambda x: x[1]) + min_score = students_sorted[0][1] + second_score = -1000 + second_score_list = list() + for i in students_sorted: + if second_score < min_score < i[1] or min_score < i[1] == second_score: + second_score_list.append(i) + second_score = i[1] + if len(second_score_list) > 0: + second_score_list_sorted = sorted(second_score_list, key=lambda x: x[0]) + for i in second_score_list_sorted: + print(i[0])