要求学生名称和成绩,直到输入完成?
我正在尝试编写一个程序,该程序存储用户进入列表中的名称/号码,并使用功能来计算学生的最大,最小值和平均值,而无需询问有多少。但是,我不知道从哪里开始。 '''
print("-----Program for printing student name with marks using list-----")
D = {}
n = int(input('How many student record you want to store?? '))
ls = []
for i in range(0, n):
x,y = input("Enter the student name and Grade: ").split()
ls.append((y,x))
ls = sorted(ls, reverse = True)
print('Sorted list of students according to their marks in descending order')
for i in ls:
print(i[1], i[0])
I am trying to write a program that stores the names/numbers the user enters in a list and uses functions to compute the maximum, minimum, and average of the students without asking how many there are. However, I don't know where to start.
'''
print("-----Program for printing student name with marks using list-----")
D = {}
n = int(input('How many student record you want to store?? '))
ls = []
for i in range(0, n):
x,y = input("Enter the student name and Grade: ").split()
ls.append((y,x))
ls = sorted(ls, reverse = True)
print('Sorted list of students according to their marks in descending order')
for i in ls:
print(i[1], i[0])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如上所述,您需要使用一个时循环,并且需要在分裂之前将输入作为单个字符串抓住,以便检查“完成”信号。
You need to use a while loop, as suggested above, and you need to grab the input as a single string before splitting, so you can check for the "done" signal.
如我的评论中所述,请使用一定的循环:
As mentioned in my comment, use a while loop like so:
使用
创建无限循环,而(true):
和内部 block使用如果(x ==“ done”):break;
。这将询问学生名称,直到输入“完成”为止。Create infinite loop with
while(true):
and inside thewhile
block useif(x == "done"): break;
. That will ask student name until "done" is inputted.