A community for students.
Here's the question you clicked on:
 0 viewing
danmei
 3 years ago
Can someone tell me why the output on this is 4 times?
Lloyd = {
"name":"Lloyd",
"homework": [90,97,75,92],
"quizzes": [ 88,40,94],
"tests": [75,90]
}
Tyler = {
"name":"Tyler",
"homework": [0,87,75,22],
"quizzes": [0,75,78],
"tests": [100,100]
}
student = ["Lloyd", "Alice", "Tyler"]
def average(student):
for person in student:
ave = float(sum(student["homework"]))/len(student["homework"])
print ave
average(Lloyd)
danmei
 3 years ago
Can someone tell me why the output on this is 4 times? Lloyd = { "name":"Lloyd", "homework": [90,97,75,92], "quizzes": [ 88,40,94], "tests": [75,90] } Tyler = { "name":"Tyler", "homework": [0,87,75,22], "quizzes": [0,75,78], "tests": [100,100] } student = ["Lloyd", "Alice", "Tyler"] def average(student): for person in student: ave = float(sum(student["homework"]))/len(student["homework"]) print ave average(Lloyd)

This Question is Closed

lh4219
 3 years ago
Best ResponseYou've already chosen the best response.1The print avg should be directly under the for

MicroBot
 3 years ago
Best ResponseYou've already chosen the best response.0actually your code is strange...what are you supposed to do? cause like that it gives only the average of the asked student but you have code u dont need at all.

MicroBot
 3 years ago
Best ResponseYou've already chosen the best response.0Lloyd = { "name":"Lloyd", "homework": [90,97,75,92], "quizzes": [ 88,40,94], "tests": [75,90] } Tyler = { "name":"Tyler", "homework": [0,87,75,22], "quizzes": [0,75,78], "tests": [100,100] } Alice={ "name":"Tyler", "homework": [0,87,75,22], "quizzes": [0,75,78], "tests": [100,100] } def average(student): ave = float(sum(student["homework"]))/len(student["homework"]) print ave average(Lloyd) this does the same thing. i set Alice as you didnt have her .
Ask your own question
Sign UpFind 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
 Engagement 19 Mad Hatter
 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.