Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 7 Online
OpenStudy (anonymous):

Hello, I'm attempting the homework assignment 2.8 and I'm getting a syntax error for clist.append(clname). I've declared clist as a variable in main and I cannot figure out why I'm getting this error. Anyone have an idea?

OpenStudy (anonymous):

I know its probably riddled with errors, but here's the code anyways. Python is giving me a syntax error on the clist in the for loop. def report_card(): clist = [] classgrade = [] classes = input("How many classes did you take? ") for num in range(0,classes): clname = raw_input("What was the name of this class? " clist.append(clname) clgrd = input("What was your grade?") classgrade.append(clgrd) n+=1

OpenStudy (anonymous):

1] Sometimes it the source of the syntax errors isn't where IDLE says it is, you're missing a bracket, probably a typo: clname = raw_input("What was the name of this class? " <-- 2] It might be different for your setup, but raw_input() isn't defined for me, did you mean input()? 3] n isn't declared before you start adding it it at n+=1. You need to say what n is before the loop. 4] Finally, 'classes' will be a string. If I type '3', input() will return the string '3', not the int 3, so you need use int(classes) 5] I haven't got the assignment, but you aren't doing anything after you fill out your lists, do you mean to return something?

OpenStudy (anonymous):

Thank you for the advice!! I can't believe that I missed that. I didn't include all of the code because it was giving me the syntax error in the for loop. Also, thanks for the advice on 'classes', that will help save a lot of pain in the end.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!