For The Record


#1

lloyd = {
"name": "Lloyd",
"homework": [],
"quizzes": [],
"tests": []
}
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]
}

lloyd['homework'] = [90.0, 97.0, 75.0, 92.0]
lloyd['quizzes'] = [88.0, 40.0, 94.0]
lloyd['tests'] = [75.0, 90.0]

students = [lloyd, alice, tyler]

for student in students:
    print "Name: %s" %student['name']
print "Homework: %s" %student['homework']
print "Quizzes: %s" %student['quizzes']
print "Tests: %s" %student['tests']
print student["name"].

#2

I keep on getting this error message...

  File "python", line 31
    print student["name"].
                         ^
SyntaxError: invalid syntax

#3

Does anyone know why exactly?


#4

Indentation, or rather lack of it. These lines should be inside the block.


#5

print "Homework: %s" %student['homework']
print "Quizzes: %s" %student['quizzes']
print "Tests: %s" %student['tests']
print student["name"].

  File "python", line 32
    print student["name"].
                         ^
SyntaxError: invalid syntax

I still get this...


#6

Python is weird. NOT AT ALL like JAVASCRIPT, but I can never seem to get anything right. I mean I have been coding for like 5 or so days. I have gotten this far, but It is pretty hard to do.


#7

Hey, will this work???

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]
}

students = [lloyd, alice, tyler]

for student in students:
    print student["name"]
    print student["homework"]
    print student["quizzes"]
    print student["tests"]

#8

Now I am on It's "Okay to be Average"

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]
}

# Add your function below!
def average(numbers):
#sum of the numbers
    total = sum(numbers)
#making the integer a float
total = float(total)
#finding average 
total = total / len(numbers)
#storing it until function is called
return total

This is what I have and it doesn't work...


#9

And now this...

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]
}

#Add your function below!
def average(numbers):
    sum (numbers)
total = float(sum(numbers))
a = total / len(numbers)
return a

numbers = [1,2,3,4,5,6,7,8,9,0]

average(numbers)

print average (numbers)

#10

Different, but alike in many respects, scope and context are generally treated the same. Javascript defines blocks with { ... }, whereas Python defines them with : and indentation below that point.

Any line that does not have the same indentation as the one before it will be considered not part of that block, unless it is further indented.

def func():
    while ___:
        if ___:
            # code

#11

Okay. I figured it out! Thenk You ROY for all of your help!


#12

Indentation is missing. Indent every line by four spaces.


#13

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]
}

#Add your function below!
def average(numbers):
    sum(numbers)
    total = sum(numbers)
    total = float(total)
    total = total / len(numbers)
    return total

I have got it Thank you...


#14

That line may be removed. My only comment would be calling the average, total.

average = total / len(numbers)

reads semantically true. Something to keep in mind when naming variables.

    return total / len(numbers)

You're welcome.


#15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.