20th Dec 2018, 11:10 AM
Balaji Pathange
Balaji Pathange - avatar
6 Antworten
+ 2
Sorry, can't upload anything to the Code Playground at the moment. Here is what I would do: s = '''5 Harry 37.21 Berry 37.21 Tina 37.2 Akriti 41 Harsh 39''' # change to input() data = s.split('\n') amount, grade_data = int(data[0]), data[1:] grades = [] for i in range(0, len(grade_data), 2): grades.append((grade_data[i], float(grade_data[i+1]))) grades = sorted(grades, key = lambda n: (n[1], n[0])) second_lowest_score = grades[1][1] print('\n'.join([val[0] for val in grades if val[1] == second_lowest_score])) # output: Berry Harry /Edit: Why did I do this? Actually you're supposed to show your attempt first
20th Dec 2018, 1:49 PM
Anna
Anna - avatar
+ 3
Please show us your attempt.
20th Dec 2018, 11:18 AM
HonFu
HonFu - avatar
+ 3
😁
20th Dec 2018, 4:22 PM
HonFu
HonFu - avatar
+ 2
Could you copy and paste the assignment? I don't want to subscribe to that website
20th Dec 2018, 12:11 PM
Anna
Anna - avatar
0
my_dict = dict() user_input = input() key, value = user_input.split(" ") Please let me know how can i solve this my_dict[key] = key print(my_dict) I am unable to parse the input to store them in the dictionary as there are more than one key names
20th Dec 2018, 11:28 AM
Balaji Pathange
Balaji Pathange - avatar
- 1
Given the names and grades for each student in a Physics class of N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade. Note: If there are multiple students with the same grade, order their names alphabetically and print each name on a new line. Input Format The first line contains an integer, N, the number of students. The subsequent lines describe each student over 2N lines; the first line contains a student's name, and the second line contains their grade. Constraints • 2<=N<=5 • There will always be one or more students having the second lowest grade. Output Format Print the name(s) of any student(s) having the second lowest grade in Physics; if there are multiple students, order their names alphabetically and print each one on a new line. Sample input : 5 Harry 37.21 Berry 37.21 Tina 37.2 Akriti 41 Harsh 39 Sample output : Berry Harry There are 5 students in this class whose names and grades are assembled to build the following list: python students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]] The lowest grade of 37.2 belongs to Tina. The second lowest grade of 37.21 belongs to both Harry and Berry, so we order their names alphabetically and print each name on a new line.
20th Dec 2018, 1:27 PM
Balaji Pathange
Balaji Pathange - avatar