944,068 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1145
  • Python RSS
Jan 7th, 2007
0

break -- Not working properly

Expand Post »
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:

Python Syntax (Toggle Plain Text)
  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:

Python Syntax (Toggle Plain Text)
  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" href="file://\\USER-7E02CF630A\My" target="_blank">\\USER-7E02CF630A\My</a> Documents\p5modstclass.py", line 77, in ?
  9. main()
  10. File "<a rel="nofollow" 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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
babutche is offline Offline
34 posts
since Oct 2006
Jan 7th, 2007
0

Re: break -- Not working properly

this is the problem
Python Syntax (Toggle Plain Text)
  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...
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Jan 7th, 2007
0

Re: break -- Not working properly

Thanks!
Reputation Points: 10
Solved Threads: 0
Light Poster
babutche is offline Offline
34 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Tkinter Window Full Size
Next Thread in Python Forum Timeline: Sorting a File





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC