python 写一个学生收集表
以下是一个简单的学生收集表的Python代码:
students = []
while True:
name = input("请输入学生姓名:")
age = int(input("请输入学生年龄:"))
gender = input("请输入学生性别:")
score = int(input("请输入学生成绩:"))
student = {"name": name, "age": age, "gender": gender, "score": score}
students.append(student)
more = input("是否继续输入?(是/否)")
if more != "是":
break
print("学生信息如下:")
for student in students:
print("姓名:{},年龄:{},性别:{},成绩:{}".format(student["name"], student["age"], student["gender"], student["score"]))
运行代码后,程序会要求你输入学生的姓名、年龄、性别和成绩。程序会将输入的信息存储在一个字典中,然后将该字典添加到学生列表中。如果你想继续输入学生信息,可以输入“是”,否则输入其他任意字符即可停止输入。
最后,程序会打印出所有学生的信息,包括姓名、年龄、性别和成绩。
原文地址: https://www.cveoy.top/t/topic/bsJu 著作权归作者所有。请勿转载和采集!