输入三个同学的成绩然后大到小排列给出python程序
可以使用列表和sort函数来实现成绩的排序:
# 输入三个同学的成绩
score1 = float(input("请输入第一个同学的成绩:"))
score2 = float(input("请输入第二个同学的成绩:"))
score3 = float(input("请输入第三个同学的成绩:"))
# 将成绩存入列表
scores = [score1, score2, score3]
# 使用sort函数进行排序(降序)
scores.sort(reverse=True)
# 打印排序后的成绩
print("从大到小排列的成绩为:", scores)
使用示例:
请输入第一个同学的成绩:85
请输入第二个同学的成绩:92
请输入第三个同学的成绩:78
从大到小排列的成绩为: [92.0, 85.0, 78.0]
原文地址: https://www.cveoy.top/t/topic/i5kh 著作权归作者所有。请勿转载和采集!