Please note that this is on Python 3.3
Here is the code:
students=int(input("How many student's score do you want to sort? "))
options=input("What do you want to sort: [Names with scores] , [Scores high to low] , [Scores averages] ? ")
options=options.upper()
if options == ("NAMES WITH SCORES") or options == ("NAME WITH SCORE") or options == ("NAME WITH SCORES") or options == ("NAMES WITH SCORE"):
a=[]
for i in range(0,students):
name=input("Enter your scores and name: ")
a.append(name)
a.sort()
print("Here are the students scores listed alphabetically")
print(a)
if options == ("SCORES HIGH TO LOW") or options == ("SCORE HIGH TO LOW"):
b=[]
number=0
for i in range(0,students):
number = number+1
print("Student "+str(number))
name2=int(input("Enter your first score: "))
name3=int(input("Enter your second score: "))
name4=int(input("Enter your third score: "))
b.append(name2)
b.append(name3)
b.append(name4)
final_score = name2 + name3 + name4
print (final_score)
b.sort(final_score)
print("Student "+str(number) )
print(b)
Here is the outcome of the code:
>>>
How many student's score do you want to sort? 2
What do you want to sort: [Names with scores] , [Scores high to low] , [Scores averages] ? scores high to low
Student 1
Enter your first score: 1
Enter your second score: 2
Enter your third score: 3
Student 2
Enter your first score: 3
Enter your second score: 5
Enter your third score: 6
14
Traceback (most recent call last):
File "H:\GCSE Computing\Task 3\Task 3.py", line 31, in <module>
b.sort(final_score)
TypeError: must use keyword argument for key function
>>>
I want the code to add the three scores of the students and sort the total scores of the students, with the according name.
For example: (2 Students)
Student 1
- Score 1 - 2
- Score 2 - 4
- Score 3 - 7
(Therefore the total is 13)
Student 2
- Score 1 - 5
- Score 2 - 1
- Score 3 - 4
(Therefore the total is 10)
(The program prints in order from highest to lowest)
"Student 1 - 15 , Student 2 - 10"