Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

mwilliams7

  • one year ago

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?

  • This Question is Closed
  1. mwilliams7
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  2. BPX
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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?

  3. mwilliams7
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.