def main(): student = Student("", 0, 0) cred = eval( input("Enter the number of credit hours for your first " + "class: ")) grade = input("Enter the grade you received for your first class: ") if grade.isalpha(): student.addLetterGrade(grade, cred) else: grade = eval(grade) student.addGrade(grade, cred) while True: cred = input("Enter the number of credit hours for your next " + "class, Q to quit: ") if cred.isalpha(): break else: cred = eval(cred) grade = input("Enter the grade you received for your next " + "class: ") if grade.isalpha(): student.addLetterGrade(grade, cred) else: grade = eval(grade) student.addGrade(grade, cred) print("\nGPA: {0}".format(student.gpa()))
def main (): #Introduction print ("This program accepts course information for one student in order to compute GPA. ") print () #Create student object a_student = Student("student", 0, 0) #User enters information for each course keepgoing = input("Type any key to enter another course or type enter to quit. ") while keepgoing != '': credits = eval(input("Please enter the number of credits in the course. ")) gradePoint = eval(input("Please enter the number grade earned by the student (ex:3.7). ")) a_student.addGrade(gradePoint, credits) keepgoing = input("Type any key to enter another course or type enter to quit. ") #Print results GPA = round(a_student.gpa(), 1) print ("The student's GPA is: ", GPA)
from student import Student # Create the students and add some grades laura = Student("Laura", "ME", 2008, True) laura.addGrade(9.5) laura.addGrade(8.5) stephan = Student("Stephan", "UM", 2016, False) stephan.addGrade(10.0) stephan.addGrade(8.5) john = Student("John", "MAPP", 2012, False) john.addGrade(6.7) john.addGrade(8.2) # Print data print("%-18s%-12s%-10s%-13s%3s" % ("Name", "Programme", "Gender", "Generation", "GPA")) print("-------------------------------------------------------------") laura.describe() stephan.describe() john.describe()
def addStudentByName(self, first, last, grades): student = Student(first, last) for grade in grades: student.addGrade(grade) self.students.append(student)
from student import Student tim = Student("Tim") lisa = Student("Lisa") tim.addGrade('A') tim.addGrade('B') tim.addGrade('B') tim.addGrade('A') tim.addGrade('E') tim.addGrade('P') lisa.addGrade('C') lisa.addGrade('B') lisa.addGrade('A') lisa.addGrade('A') lisa.addGrade('A') lisa.addGrade('A') print("{0}'s GPA is: {1}".format(tim.getName(), tim.getGpa())) print("{0}'s GPA is: {1}".format(lisa.getName(), lisa.getGpa()))
from student import Student s1 = Student("Jon Doe") f = s1.getFullName() print(f) s1.addGrade('HW', (1, 90)) s1.addGrade('tests', (1, 85)) grades2 = s1.getGrades('HW') print(grades2)