-1
Please note that this is on Python 3.3如何对变量中的整数进行排序?
下面是代码:
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)
这里是代码的结果:
>>>
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
>>>
我想要的代码中加入了学生和排序的三个分数学生的总分数,以及相应的名称。
例如: (2名学生)
学生1
- 分数1 - 2
- 分数2 - 4
- 评分3 - 7
(因此总数是13)
学生2
- 分数1 - 5
- 分数2 - 1
- 分数3 - 4
(因此总是10)
(为了从最高到最低的程序打印)“学生1 - 15,学生2 - 10”
这不起作用。这里是结果: – Anonymous 2015-02-05 15:25:33
你想排序多少个学生的分数? 2 你想排序什么:[有得分的名字],[得分高到低],[得分平均值]?得分从高到低 你叫什么名字?测试 输入您的第一得分:1 输入您的第二得分:2 输入第三得分:3 你是什么nametest 2 输入第一得分:3 输入第二得分:4 输入您的第三得分:5 回溯(最近最后调用): 文件 “H:\ GCSE计算\任务3 \任务3.py”,第31行,在 b.sort(键= final_score) 类型错误: 'INT' 目的是不可回调 >>> –
Anonymous
2015-02-05 15:26:04
@ThifyanRavinehru,是的,你需要传递一个函数作为关键,python如何使用int进行排序? – 2015-02-05 15:27:27