Student Becomes Teacher: Just Weight and See


#1

Hey there,

Can anyone see what is wrong with my 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]
}
# Add your function below!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    total = total / len(numbers) 
    return total
    
def get_average(alice):
    homework = average(alice["homework"])
quizzes = average(alice["quizzes"])
tests = average(alice["tests"])

homework_updated = 0.6 * homework
quizzes_updated = 0.1 * quizzes
tests_updated = 0.3 * tests

total = sum(homework_updated + quizzes_updated +  tests_updated)
total = int(total)
return total

For some reason im having a formatting problem on the forum
^^^ my last 8 lines of code are indented in the codecademy console.

I keep getting this error:-

" get_average(alice) raised the following error: 'float' object is not iterable"


#2

Ive simplified my code (see below) but I am still getting this error message even though I have edited the bit of code 'get_average(alice)':-

def get_average(student):
    homework = average(alice["homework"])
quizzes = average(alice["quizzes"])
tests = average(alice["tests"])

homework = 0.6 * homework
quizzes = 0.1 * quizzes
tests = 0.3 * tests

total = sum(homework + quizzes + tests)

return total

"get_average(alice) raised the following error: 'float' object is not iterable"


#3

Ive updated my code again but I think im getting further away

def get_average(student):

    homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
student = alice
get_average(alice)

"homework" = 0.6 * "homework"
"quizzes" = 0.1 * "quizzes"
"tests" = 0.3 * "tests"

total = sum(homework + quizzes + tests)
    
print total

(sorry the indentation and formatting in my posted code is all over the place I need to find a better way to post it)


#4

Your error message says which call was used to cause the crash.

So do that call yourself and see where the crash happens. Look closer at that line and if you're uncertain about what variables hold then either look at what was assigned to them or use prints to find out.

I edited your last post, click edit on it to see how I marked your code as code.


#5

Hi,

Its been a while (im learning this slowly). I decided to write the code from scratch. Here is what I am have got latest

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):
    total = sum(numbers)
    total = float(total)
    total = total / len(numbers) 
    return total
    
def get_average(student):

    homework = average(student[“homework”])
    quizzes = average(student[“quizzes”])
    tests = average(student[“tests”])

    return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

I will try using print statements again like you suggested but can you shed any light please?

Also I still dont know how to post the code. I checked the edit function in my previous post. Its looks like

apostrophe, apostrophe , apostrophe then the word 'python' all underlined then at the end three more apostrophes


#6

In chrome its just saying 'something went wrong' . In Firefox its just freezing.


#7

Ive changed it to this now (Ive unindented the final line)

def get_average(student):

    print homework = average(student[“homework”])
    print quizzes = average(student[“quizzes”])
    print tests = average(student[“tests”])

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

I am just getting this error message below

and then when I try again the button goes blue like below

I am trying in Firefox and Chrome but similar problems. I am going to shut down for a bit then maybe try in internet explorer (or whatever its called now) and also maybe run a virus scan.

Im never getting email notifications when people reply to these threads so thats why it took me 13 days to reply. It might be they are going into my gmail social folder which i rarely look at.


#8

I ended up looking on the forums for the answer

This is what I found...

def get_average(student):
    lloyd_homework=average(student['homework'])
    lloyd_quizzes=average(student['quizzes'])
    lloyd_tests=average(student['tests'])
    lloyd_average_score=0.1*lloyd_homework+0.3*lloyd_quizzes\
    +0.6*lloyd_tests
    return lloyd_average_score

I am wondering how this compares to my own code? How is it different? Why is it different. How does it work?

def get_average(student):

    homework = average(student[“homework”])
    quizzes = average(student[“quizzes”])
    tests = average(student[“tests”])

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

#9

Mystery errors aren't very helpful on their own, but you can still investigate them by running your code and making observations. Since the environment crashed, you'll need another one. When I run your code locally, this is how Python responds:

  File "bytec.py", line 29
SyntaxError: Non-ASCII character '\xe2' in file bytec.py on line 29, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Were you using some kind of word processor to write the code? (As opposed to a plain text editor)


#10

Hi ionatan,

Hi there. Yes actually I wrote the code in Microsoft Word. I guess that's a bit of a no-no. I use word for making notes for my job but I guess its not set up for writing code.

I did manage to work out the code

instead of

def get_average(student):

    homework = average(student[“homework”])
    quizzes = average(student[“quizzes”])
    tests = average(student[“tests”])

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

it should be

def get_average(student):

    homework = average(student[“homework”])
    quizzes = average(student[“quizzes”])
    tests = average(student[“tests”])

score = 0.1 * homework + 0.3 * quizzes + 0.6 * tests
return score

I know I am a slow learner with coding but I am really enjoying it! One of my goals is to create an app that streams audio content for the radio production company I work for.


#11

looking good :slight_smile:


#12

Thanks ktsui :slight_smile: Thanks for the support.