break -- Not working properly

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 34
Reputation: babutche is an unknown quantity at this point 
Solved Threads: 0
babutche babutche is offline Offline
Light Poster

break -- Not working properly

 
0
  #1
Jan 7th, 2007
I am having a problem getting my "break" to work correctly in this program. Can anyone help me see what I am doing wrong?

This is my program:

  1. import string
  2. import math
  3. class Student:
  4. def __init__(self, name, hours, qpoints):
  5. self.name = name
  6. self.hours = float(hours)
  7. self.qpoints = float(qpoints)
  8. def getName(self):
  9. return self.name
  10. def getHours(self):
  11. return self.hours
  12. def getQpoints(self):
  13. return self.qpoints
  14. def gpa(self):
  15. return self.qpoints/self.hours
  16. def addGrade(self, gradePoint, credits):
  17. self.hours = credits
  18. self.qpoints = credits*gradePoint
  19. def main():
  20. print "This program is a modified version of the student class. It adds"
  21. print "a mutator method that records a grade and calculates the GPA for"
  22. print "the student"
  23. print
  24. print
  25. grade = input("Enter gradepoint for course (Enter to quit): ")
  26. print
  27. credits = input("Enter number of credit hours for course (Enter to quit): ")
  28.  
  29. stu = Student("stu", 0.0, 0.0)
  30. while 1:
  31. grade_str = raw_input("Enter next gradepoint (Enter to quit): ")
  32. if grade_str == "":
  33. break
  34. try:
  35. grade = float(grade_str)
  36. except ValueError:
  37. print "Error, use floating point number"
  38. return
  39. credits_str = raw_input("Enter next credit hours (Enter to quit): ")
  40. try:
  41. credits = float(credits_str)
  42. except ValueError:
  43. print "Error, use floating point number"
  44. return
  45. stu.addGrade(grade, credits)
  46.  
  47. if stu.getHours() == 0.0 :
  48. print "Zero credit hours recorded"
  49. else:
  50. print "Final GPA = ", stu.gpa()
  51.  
  52. if __name__ == '__main__':
  53. main()

This is the error:

  1. >>>
  2. This program is a modified version of the student class. It adds
  3. a mutator method that records a grade and calculates the GPA for
  4. the student
  5.  
  6. Enter gradepoint for course (Enter to quit):
  7. Traceback (most recent call last):
  8. File "<a rel="nofollow" class="t" href="file://\\USER-7E02CF630A\My" target="_blank">\\USER-7E02CF630A\My</a> Documents\p5modstclass.py", line 77, in ?
  9. main()
  10. File "<a rel="nofollow" class="t" href="file://\\USER-7E02CF630A\My" target="_blank">\\USER-7E02CF630A\My</a> Documents\p5modstclass.py", line 38, in main
  11. grade = input("Enter gradepoint for course (Enter to quit): ")
  12. File "<string>", line 0
  13.  
  14. ^
  15. SyntaxError: unexpected EOF while parsing
  16. >>>

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 149
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: break -- Not working properly

 
0
  #2
Jan 7th, 2007
this is the problem
  1. grade = input("Enter gradepoint for course (Enter to quit): ")

input() expects a number. when you just press enter, it gives error
maybe a try:except can solve the problem...
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 34
Reputation: babutche is an unknown quantity at this point 
Solved Threads: 0
babutche babutche is offline Offline
Light Poster

Re: break -- Not working properly

 
0
  #3
Jan 7th, 2007
Thanks!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC