#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Smile I have a trouble when coding


    Code:
    lloyd = {
        "name": "Lloyd",
        "homework": [90.0, 97.0, 75.0, 92.0],
        "quizzes": [88.0, 40.0, 94.0],
        "tests": [75.0, 90.0] } 
    alice = {
        "name": "Alice",
        "homework": [100.0, 92.0, 98.0, 100.0],
        "quizzes": [82.0, 83.0, 91.0],
        "tests": [89.0, 97.0] } 
    tyler = {
        "name": "Tyler",
        "homework": [0.0, 87.0, 75.0, 22.0],
        "quizzes": [0.0, 75.0, 78.0],
        "tests": [100.0, 100.0] }
    
    n= ["lloyd", "alice", "tyler"]
    
    def average(n):
        return sum(n)/len(n)
    
    a=0 for name in n:
        a += (average(name["homework"])*0.1 + average(name["quizzes"])*0.3 + average(name["tests"])*0.6) print (a/len(n))
    I am just a beginner in Python programming, and when coding, I am facing a trouble. When I run my code, the compiler said name["homework"], name["quizzes"], name["tests"] is string, not are lists of numbers. Could you help me to find out any error in my code?
    Last edited by harrybotboy; June 6th, 2013 at 10:44 AM. Reason: Modified some things wrong in code
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    lloyd, for example, is a dictionary, as is alice, and tyler. lloyd[homework], for instance (note the square brackets), is the list, [90.0, 97.0, 75.0, 92.0].
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Thumbs up


    Originally Posted by rrashkin
    lloyd, for example, is a dictionary, as is alice, and tyler. lloyd[homework], for instance (note the square brackets), is the list, [90.0, 97.0, 75.0, 92.0].
    OH, thank you, I fixed my code and I ran smoothly. Thank you very much

IMN logo majestic logo threadwatch logo seochat tools logo