Hi,
I did get the problem fixed with my "break" not working properly but now my ValueError will not work properly. If you enter a number that is not a floating number it should create a value error(as a matter of fact it did before I fixed my other problem ("break"). Can anyone help, please! Thanks!!!
import string
import math
class Student:
def __init__(self, name, hours, qpoints):
self.name = name
self.hours = float(hours)
self.qpoints = float(qpoints)
def getName(self):
return self.name
def getHours(self):
return self.hours
def getQpoints(self):
return self.qpoints
def gpa(self):
return self.qpoints/self.hours
def addGrade(self, gradePoint, credits):
self.hours = credits
self.qpoints = credits*gradePoint
def main():
print "This program is a modified version of the student class. It adds"
print "a mutator method that records a grade and calculates the GPA for"
print "the student"
print
stu = Student("stu", 0.0, 0.0)
while 1:
print
grade_str = raw_input("Enter gradepoint or (Enter to quit): ")
if grade_str == "":
break
try:
grade = float(grade_str)
except ValueError:
print "Error, use floating point number"
return
print
credits_str = raw_input("Enter credit hours or (Enter to quit): ")
if credits_str == "":
break
try:
credits = float(credits_str)
except ValueError:
print "Error, use floating point number"
return
stu.addGrade(grade, credits)
if stu.getHours() == 0.0 :
print
print "Zero gradepoints or credit hours recorded"
print
else:
print "Final GPA = ", stu.gpa()
print
Thank You!!