python - eval () Unexpected EOF while parsing -
python - eval () Unexpected EOF while parsing -
so i'm trying 2 inputs separate usernames credit hours , every time after i've exited loop unexpected eof.
fresh = [] soph = [] jun = [] sen = [] def classify(cr, un): if cr <= 27: fresh.append(un) print(un, 'is freshman.\n') elif 28 <= cr <= 56: soph.append(un) print(un, 'is sophomore.\n') elif 57 <= cr <= 84: jun.append(un) print(un, 'is junior.\n') elif cr >= 85: sen.append(un) print(un, 'is senior\n') def main(): united nations = input('student: ') cr = eval(input('credits: ')) while united nations , cr != '': united nations = input('student: ') cr = eval(input('credits: ')) classify(cr, un)
specifically error is:
file "./class.py", line 58, in <module> main() file "./class.py", line 51, in main cr = eval(input('credits: ')) file "<string>", line 0
i'm not sure if it's related (or if it's i'm overlooking) have come in through credit in order exit loop. shouldn't loop exit after pressing come in when pupil comes due , operator?
edit: added classify func. don't think problem though, i've tried removing , still brings me eof.
you shouldn't using eval()
turn string integer. utilize int
instead.
def main(): united nations = input('student: ') cr = input('credits: ') classify(int(cr), un) while united nations , cr: united nations = input('student: ') cr = input('credits: ') classify(int(cr), un)
credits must still entered after skipping pupil name because while
status evaluated before going code block, not after every statement in block. if want stop when user skips pupil or credit value, this:
def main(): while 1: united nations = input('student: ') if not un: break cr = input('credits: ') if not cr: break classify(int(cr), un)
and, of course, utilize input
python 3, , raw_input
python 2.
python
Comments
Post a Comment