是否可以选择为商标添加主题?
Is there a option to add a subject to the mark?
我构建了一个程序,其中包含学生的 ID 和每个科目的分数列表
不同的学生选修了不同数量的科目。
我正在尝试将主题的名称添加到他的标记附近,但找不到任何解决方案。
下面是我写的代码:
def GetStudentDataFromTeacher ():
D ={}
while True:
StudentId = input ("Enter The Student ID:")
StudentMarks = input ("Enter The Student Each Marks:")
MoreStudents = input ('If you dont have more student type "no":')
if StudentId in D:
print (StudentId, "**You Already Type this student")
else:
D[StudentId] = StudentMarks.split (",")
if MoreStudents.lower() == "no":
return D
谢谢!!
您可以要求用户以特定格式输入成绩,然后将此字符串转换为字典,其中键为主题,值为成绩。
例如,您可以要求用户按以下格式输入:<subject1>--<grade1>,<subject2>--<grade2>
.
代码将是:
def get_students_data():
students_grades = {}
while True:
student_id = input("Enter The Student ID:")
grades = input("Enter the student grades in the following format <subject1>--<grade1>,<subject2>--<grade2>:")
more_students = input('If you dont have more student type "no":')
if student_id in students_grades:
print(student_id, "**You Already Type this student")
else:
students_grades[student_id] = {subject_grade.split("--")[0]: subject_grade.split("--")[1] for subject_grade
in grades.split(",")}
if more_students.lower() == "no":
return students_grades
print(get_students_data())
输出将是:
# Enter The Student ID: 1
# Enter the student grades in the following format <subject1>--<grade1>,<subject2>--<grade2>:: math--90,history--70
# If you dont have more student type "no": no
{'1': {'math': '90', 'history': '70'}}
可能有更好的方法来实现此行为(您可以以更加结构化的方式创建包含所有成绩数据的 json 文件,然后向用户询问其路径并解析它)但是如果您想坚持您的解决方案,上面的代码片段将起作用。
我构建了一个程序,其中包含学生的 ID 和每个科目的分数列表 不同的学生选修了不同数量的科目。
我正在尝试将主题的名称添加到他的标记附近,但找不到任何解决方案。
下面是我写的代码:
def GetStudentDataFromTeacher ():
D ={}
while True:
StudentId = input ("Enter The Student ID:")
StudentMarks = input ("Enter The Student Each Marks:")
MoreStudents = input ('If you dont have more student type "no":')
if StudentId in D:
print (StudentId, "**You Already Type this student")
else:
D[StudentId] = StudentMarks.split (",")
if MoreStudents.lower() == "no":
return D
谢谢!!
您可以要求用户以特定格式输入成绩,然后将此字符串转换为字典,其中键为主题,值为成绩。
例如,您可以要求用户按以下格式输入:<subject1>--<grade1>,<subject2>--<grade2>
.
代码将是:
def get_students_data():
students_grades = {}
while True:
student_id = input("Enter The Student ID:")
grades = input("Enter the student grades in the following format <subject1>--<grade1>,<subject2>--<grade2>:")
more_students = input('If you dont have more student type "no":')
if student_id in students_grades:
print(student_id, "**You Already Type this student")
else:
students_grades[student_id] = {subject_grade.split("--")[0]: subject_grade.split("--")[1] for subject_grade
in grades.split(",")}
if more_students.lower() == "no":
return students_grades
print(get_students_data())
输出将是:
# Enter The Student ID: 1
# Enter the student grades in the following format <subject1>--<grade1>,<subject2>--<grade2>:: math--90,history--70
# If you dont have more student type "no": no
{'1': {'math': '90', 'history': '70'}}
可能有更好的方法来实现此行为(您可以以更加结构化的方式创建包含所有成绩数据的 json 文件,然后向用户询问其路径并解析它)但是如果您想坚持您的解决方案,上面的代码片段将起作用。