| | |
break -- Not working properly
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 34
Reputation:
Solved Threads: 0
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:
This is the error:
Thanks!
This is my program:
Python Syntax (Toggle Plain Text)
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" grade = input("Enter gradepoint for course (Enter to quit): ") credits = input("Enter number of credit hours for course (Enter to quit): ") stu = Student("stu", 0.0, 0.0) while 1: grade_str = raw_input("Enter next gradepoint (Enter to quit): ") if grade_str == "": break try: grade = float(grade_str) except ValueError: print "Error, use floating point number" return credits_str = raw_input("Enter next credit hours (Enter to quit): ") try: credits = float(credits_str) except ValueError: print "Error, use floating point number" return stu.addGrade(grade, credits) if stu.getHours() == 0.0 : print "Zero credit hours recorded" else: print "Final GPA = ", stu.gpa() if __name__ == '__main__': main()
This is the error:
Python Syntax (Toggle Plain Text)
>>> This program is a modified version of the student class. It adds a mutator method that records a grade and calculates the GPA for the student Enter gradepoint for course (Enter to quit): Traceback (most recent call last): File "<a rel="nofollow" class="t" href="file://\\USER-7E02CF630A\My" target="_blank">\\USER-7E02CF630A\My</a> Documents\p5modstclass.py", line 77, in ? main() File "<a rel="nofollow" class="t" href="file://\\USER-7E02CF630A\My" target="_blank">\\USER-7E02CF630A\My</a> Documents\p5modstclass.py", line 38, in main grade = input("Enter gradepoint for course (Enter to quit): ") File "<string>", line 0 ^ SyntaxError: unexpected EOF while parsing >>>
Thanks!
•
•
Join Date: Apr 2006
Posts: 149
Reputation:
Solved Threads: 40
this is the problem
input() expects a number. when you just press enter, it gives error
maybe a try:except can solve the problem...
Python Syntax (Toggle Plain Text)
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...
![]() |
Similar Threads
- Mouse not working properly in OS X (OS X)
- Keyboard not working properly (USB Devices and other Peripherals)
- ValueError - Not Working (Python)
- CD - DVD ROM Drive not working properly (Storage)
- Intel D815EEA PCI cards are not working properly (Windows NT / 2000 / XP)
- Scanner not working (USB Devices and other Peripherals)
- LAN is not Working Properly After Changing Switch From 10 Mbps 100 Mbps (Networking Hardware Configuration)
- msn messenger not working.. SSL (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Tkinter Window Full Size
- Next Thread: Sorting a File
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format ftp function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere web webservice wikipedia windows wxpython xlib





