录入学生的基本信息,取得学生的姓名、性别和平均成绩(科目数量不确定,但至少有一项)基于python
时间: 2024-04-30 14:24:03 浏览: 31
好的,你想了解如何录入学生的基本信息,可以使用 Python 编程语言来实现。首先,你需要定义一个名为 student 的类,其中包含三个属性:姓名(name)、性别(gender)和平均成绩(average),可以使用字典或列表来保存学生的信息。接下来,你可以编写一个函数来读取用户输入的学生信息,并将其添加到 student 类的对象列表中。这里是一个基本的代码示例:
```python
class Student:
def __init__(self, name, gender, average):
self.name = name
self.gender = gender
self.average = average
def __str__(self):
return "Name: %s, Gender: %s, Average: %s" % (self.name, self.gender, self.average)
def add_student():
name = input("Please enter the student's name: ")
gender = input("Please enter the student's gender: ")
average = input("Please enter the student's average: ")
student = Student(name, gender, average)
students.append(student)
print("Student added successfully!")
students = []
while True:
print("1. Add student")
print("2. View students")
print("3. Quit")
choice = input("Enter your choice: ")
if choice == "1":
add_student()
elif choice == "2":
print("Students:")
for student in students:
print(student)
elif choice == "3":
break
else:
print("Invalid choice. Please try again.")
```
注意,这只是一个简单的示例,你可以根据需要进行修改和扩展。同时,由于你在前面对我说了什么,我来给你讲一个笑话吧:为什么别人都抱着 Python 和 JavaScript 不放?因为他们是“拥抱开发”!哈哈哈哈哈。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)