我遇到一个问题,就是在定义所有学生的分数并去增加分数之后。它没有给我一个错误,但是只是在此处结束了代码。
代码中断的地方:
def particular_class():
sname = input("Students name?: ")
for students in Students:
if (students == sname):
print("""
1. Math
2. English
3. Comp Sci
4. Science
5. History
6. French
7. Quit""")
grade = int(input("What subject would you like to input a grade for?\n"))
if grade == 1:
Math.Add_grades(Students[students])
elif grade == 2:
English.Add_grades(Students[students])
elif grade == 3:
Comp_sci.Add_grades(Students[students])
elif grade == 4:
Science.Add_grades(Students[students])
elif grade == 5:
History.Add_grades(Students[students])
elif grade == 6:
French.Add_grades(Students[students])
elif grade == 7:
Choice()
整个代码:
Students = {}
Stud = {}
Kids = []
class Student:
def __init__(self):
self.classes = []
self.name = input("What is the name of the student?\n")
Done = True
while(Done):
grade = int(input("Please Enter a grade between 9 - 12\n"))
if grade < 9:
print()
elif grade > 12:
print()
else:
Done = False
self.age = int(input("What is the age of the student?\n"))
Stud[self.name] = "Grade", grade, "Age", self.age
self.grade_storage = {}
self.Total_grades = []
self.Class_Average = {}
self.Average = []
global av
av = 0
def Add_students(s):
Students[s.name] = s
print()
print(Stud)
print("Students in your class:", len(Students))
Choice()
def Add_grades(self, student):
global av
Assignment = input("Name of Assignment?\n")
Grade = int(input("Grade for Assignement?\n"))
student.Total_grades.append(Grade)
student.Class_Average[Assignment] = Grade
Num_of_Assignments = len(student.Class_Average)
total = sum(student.Total_grades)
student.Average = total/Num_of_Assignments
av = round(student.Average, 2)
Choice()
def assignments(self, student):
print(student.Class_Average)
Choice()
def GPA(self, student):
print("Average", student.Average)
avg = av * 100
int(avg)
y = 0
for x in range(0, int(avg)):
y += 0.04
z = y/100
c = round(z,2)
print("GPA:", c)
class Genesis:
def Remove_students(self):
name = input("What is the name of the student?\n")
del Students[name]
print(Students)
print("Students in your class:", len(Students))
Choice()
def Students(self):
print()
Kids.sort()
for Studs in Kids:
print(Studs)
print("Students in your class:", len(Students))
Choice()
print("You require a minimum of 6 students to have a class, please add your students:")
Math = Student()
English = Student()
Science = Student()
History = Student()
French = Student()
Comp_sci = Student()
def assignments():
sname = input("Students name?: ")
for students in Students:
if (students == sname):
print("""
1. Math
2. English
3. Comp Sci
4. Science
5. History
6. French
7. Quit""")
grade = int(input("What subject would you like to see assignments for?\n"))
if grade == 1:
Math.assignments(Students[students])
elif grade == 2:
English.assignments(Students[students])
elif grade == 3:
Comp_sci.assignments(Students[students])
elif grade == 4:
Science.assignments(Students[students])
elif grade == 5:
History.assignments(Students[students])
elif grade == 6:
French.assignments(Students[students])
elif grade == 7:
Choice()
def particular_class():
sname = input("Students name?: ")
for students in Students:
if (students == sname):
print("""
1. Math
2. English
3. Comp Sci
4. Science
5. History
6. French
7. Quit""")
grade = int(input("What subject would you like to input a grade for?\n"))
if grade == 1:
Math.Add_grades(Students[students])
elif grade == 2:
English.Add_grades(Students[students])
elif grade == 3:
Comp_sci.Add_grades(Students[students])
elif grade == 4:
Science.Add_grades(Students[students])
elif grade == 5:
History.Add_grades(Students[students])
elif grade == 6:
French.Add_grades(Students[students])
elif grade == 7:
Choice()
def Choice():
print("""1. Add Students
2. Add Grades
3. View Grade
4. Remove Student
5. View Students
6. GPA\n""")
Attendance = Genesis()
Option = int(input("Please choice an option.\n"))
if Option == 1:
global s
s = Student()
Student.Add_students(s)
elif Option == 2:
particular_class()
elif Option == 3:
assignments()
elif Option == 4:
Attendance.Remove_students()
elif Option == 5:
Attendance.Students()
elif Option == 6:
print()
Choice()
答案 0 :(得分:0)
因为没有名字的学生,所以没有选择,例外之类的电话。我建议使用while True:
进行菜单,而不是每次都进行递归调用。您的方法将很快使堆栈溢出。