输入两个学生的学号、姓名和成绩,输出成绩较高学生的学号、姓名和成
时间: 2024-06-14 07:05:33 浏览: 102
以下是一个示例代码,用于输入两个学生的学号、姓名和成绩,并输出成绩较高的学生的学号、姓名和成绩:
```python
class Student:
def __init__(self, student_id, name, score):
self.student_id = student_id
self.name = name
self.score = score
student1 = Student(input("请输入学生1的学号:"), input("请输入学生1的姓名:"), int(input("请输入学生1的成绩:")))
student2 = Student(input("请输入学生2的学号:"), input("请输入学生2的姓名:"), int(input("请输入学生2的成绩:")))
if student1.score > student2.score:
print("成绩较高的学生是:")
print("学号:", student1.student_id)
print("姓名:", student1.name)
print("成绩:", student1.score)
elif student1.score < student2.score:
print("成绩较高的学生是:")
print("学号:", student2.student_id)
print("姓名:", student2.name)
print("成绩:", student2.score)
else:
print("两个学生的成绩相等。")
print("学生1的信息:")
print("学号:", student1.student_id)
print("姓名:", student1.name)
print("成绩:", student1.score)
print("学生2的信息:")
print("学号:", student2.student_id)
print("姓名:", student2.name)
print("成绩:", student2.score)
```
阅读全文