# 6. Just Weight and See

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
get_average(alice) raised the following error: can’t multiply sequence by non-int of type ‘float’

<What do you expect to happen instead?>
I assume I got the def average(numbers) function right. Did I misunderstand in any way for the ‘float’ exercise? And how does the program know to input the three dictionaries Lloyd, Alice, and Tyler as the variables for the parameter number? I don’t quite get this part too. Thanks.

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

def average(numbers):
total = float(sum(numbers))/len(numbers)

def get_average(student):
homework = average(student["homework"]),
quizzes = average(student["quizzes"]),
tests =average(student["tests"]),
return homework *0.1+ quizzes *0.3 + tests * 0.6
``````

#2

your get_average function, the following variables:

homework
quizzes
tests

Are of data type tuple (immutable list), why?

these variables are tuples because of the usages of commas at the end of the lines where you declare the variables:

``````def get_average(student):
homework = average(student["homework"]),
quizzes = average(student["quizzes"]),
tests =average(student["tests"]),
print homework, type(homework)
return homework *0.1+ quizzes *0.3 + tests * 0.6

get_average(lloyd)
``````

see how homework is of type tuple if you run this code? in case `type()` isn’t covered, take a guess what it does. It gives use the data type

#3

I put in the code line you suggested here, but the error still remains and did not really print out anything. I understand homework is a type of data type where you can store values, but I am not really sure what tuple represents in this context and what it suggests in the data type.

I am guessing syntax type() indicates what this data set comes from? It may tell the user the homework data come from get_average function?

How does this information can help me to solve my issue with “get_average(alice) raised the following error: can’t multiply sequence by non-int of type ‘float’?”

Thanks

#4

@stetim94 is helping you understand how you constructed your code into a tuple by placing a comma at the end of each line. See the comma at the end of lines for `homework`, `quizzes`, and `tests`?

He was helping you to visualize the data type with this `print homework, type(homework)` line of code. You can remove that line of code for the exercise.

For this exercise, you do not want to create a tuple. Rather, you merely want to get the average for homework and store that into a variable, then repeat for the others.

Look at your code. If placing the comma at the end of the line caused it change data types, what do you need to do in your code to get rid of the tuple?

#5

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