要求学生名称和成绩,直到输入完成?

发布于 2025-01-21 11:45:03 字数 516 浏览 2 评论 0原文

我正在尝试编写一个程序,该程序存储用户进入列表中的名称/号码,并使用功能来计算学生的最大,最小值和平均值,而无需询问有多少。但是,我不知道从哪里开始。 '''

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情何以堪。 2025-01-28 11:45:03

如上所述,您需要使用一个时循环,并且需要在分裂之前将输入作为单个字符串抓住,以便检查“完成”信号。

print("-----Program for printing student name with marks using list-----")
ls = []
while True:
    s = input("Enter the student name and Grade: ")
    if s == "done":
        break
    x,y = s.split()
    ls.append((y,x))

ls.sort(reverse = True)
print('Sorted list of students according to their marks in descending order')
for i in ls:
    print(i[1], i[0])

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.

print("-----Program for printing student name with marks using list-----")
ls = []
while True:
    s = input("Enter the student name and Grade: ")
    if s == "done":
        break
    x,y = s.split()
    ls.append((y,x))

ls.sort(reverse = True)
print('Sorted list of students according to their marks in descending order')
for i in ls:
    print(i[1], i[0])
数理化全能战士 2025-01-28 11:45:03

如我的评论中所述,请使用一定的循环:

print("-----Program for printing student name with marks using list-----")

D = {} # Not sure what this is for

ls = []

while True:
    user_input = input("Enter the student name and Grade: (done if complete)")

    # Break and exit the loop if done
    if user_input.lower() == 'done':
        break

    # Otherwise, continue adding to list
    x,y = user_input.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])

As mentioned in my comment, use a while loop like so:

print("-----Program for printing student name with marks using list-----")

D = {} # Not sure what this is for

ls = []

while True:
    user_input = input("Enter the student name and Grade: (done if complete)")

    # Break and exit the loop if done
    if user_input.lower() == 'done':
        break

    # Otherwise, continue adding to list
    x,y = user_input.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])
〗斷ホ乔殘χμё〖 2025-01-28 11:45:03

使用创建无限循环,而(true):和内部 block使用如果(x ==“ done”):break;。这将询问学生名称,直到输入“完成”为止。

Create infinite loop with while(true): and inside the while block use if(x == "done"): break;. That will ask student name until "done" is inputted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文