def main():
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
You want the "try :" statement as the first statement after "while 1:". That will give you an error message if a number is not entered. If an integer is entered, it can legally be type cast into a float. If a float is entered and you try to convert it into an integer you will get an error, so inserting a "grade_int = int(grade_str) and another try:/except: statement will do the trick, but it seems cumbersome. You could also use divmod(grade_float, 1) and check for a remainder. Can someone legimately have a gpa of 70? If so you want to be able to enter an integer. If the gpa is entered as 0.70, then you want to test that the float is less than one.
while 1:
try:
print
grade_str = raw_input("Enter gradepoint or (Enter to quit): ")
if grade_str == "":
break
grade = float(grade_str)
try :
grade_int = int(grade_str)
print "Error, use floating point number"
except :
print grade
except ValueError:
print "Error, use floating point number"
Edit: Added additional try/except statement. Sorry, I did the first post in a hurry.
Edit-2: I would suggest that you have a GetInput function that you would pass "grade point" or "credit hours" to, it would get the input and convert to floating point and return the number or a -1 if bad data and then exit with an 'enter'. You are doing the same thing twice, so putting this is in a function is more efficient and breaks the code up into smaller chunks, which is easier to debug. Looks like you are just about finished though. Any plans for a Tkinter or other GUI interface?