Monday, July 1, 2013

Codeacademy (Python) Student becomes teacher


[Codecacademy] Python Challenge 1

Student Becomes the Teacher

Had some trouble finding tutorials so posted after I completed.

'''

1. Lesson Number One

Fill out three Dictionaries named Lloyd , Alice and Tyler . Give each dictionary the keys "name," "Homework," "quizzes," and "tests." Have the "name" Key Reference the name of the student and the others keys Reference an empty list ''' Lloyd = {"name": "Lloyd", "homework": [], "quizzes": [], "tests": []} Alice = {"name": "Alice", "homework": [], "quizzes": [], "tests": []} Tyler = {"name": "Tyler", "homework": [], "quizzes": [], "tests": []} '''
2. What's the Score?

Now fill your Lloyd dictionary with the Appropriate Scores. To save you some time, We've filled out the rest for you.


Homework: 90, 97, 75, 92
Quizzes: 88, 40, 94
Test Scores: 75, 90
'''

Lloyd = { "Name": "Lloyd", "Homework": [90, 97, 75, 92], "Quizzes": [88, 40, 94], "Tests": [75, 90] } 
Alice = { "Name": "Alice", "Homework": [100,92,98,100], "Quizzes": [82,83,91], "Tests": [89,97] } 
Tyler = { "Name": "Tyler", "Homework": [0,87,75,22], "Quizzes": [0,75,78], "Tests": [100,100] }



'''
3. Put It TogetherNow put the Lloyd, Alice and Tyler Dictionaries in a List called students
'''
students = [Lloyd, Alice, Tyler]
'''

4.Print out All the Data in your students

''' students = [Lloyd, Alice, Tyler] for x in students: print x["name"], print x["homework"], print x["quizzes"], print x["tests"] '''

Just Average

1. It's Okay to be Average

First, Write a function average that takes the average value of a List filled only with Numbers. ''' def average (list): aver = sum (list) / len (list) return aver '''

2. Just Weight and See (weighted)

Write the function getAverage student that takes a dictionary as input and calculates his / her weighted average. Use your average function to Help. Homework is 10%, quizzes are 30% and tests are 60%. ''' def getAverage (dic): weight_average = (average (dic ["homework"]) * 0.1 + average (dic ["quizzes"]) * 0.3 + average (dic ["tests"]) * 0.6) return weight_average '''

3.Sending a Letter

Now Write a getLetterGrade function that takes Score as input and Returns a String with the letter that that student should Receive Grade. ''' def getLetterGrade (score): if 90 <= round (score): return "A" elif 80 <= round (score) <90: return "B" elif 70 <= round (score) <80: return "C" elif 60 <= round (score) <70: return "D" else: return "F" '''4. Part of the Whole Write a function called getClassAverage that takes your student List as input to Compute the average of your entire Class. ''' def getClassAverage (list): sum = 0 for x in list: sum = sum + getAverage (x) return sum / len (list) '''

5. How is Everybody Doing?

Finally, run your getClassAverage function on your students to Print out the Numerical Grade Grade AND the letter. ''' Lloyd = { "Name": "Lloyd", "Homework": [90,97,75,92], "Quizzes": [88,40,94], "Tests": [75,90] } Alice = { "Name": "Alice", "Homework": [100,92,98,100], "Quizzes": [82,83,91], "Tests": [89,97] } Tyler = { "Name": "Tyler", "Homework": [0,87,75,22], "Quizzes": [0,75,78], "Tests": [100,100] } def average (stuff): return sum (stuff) / len (stuff) def getLetterGrade (score): if 90 <= round (score): return "A" elif 80 <= round (score) <90: return "B" elif 70 <= round (score) <80: return "C" elif 60 <= round (score) <70: return "D" else: return "F" def getAverage (kid): bar = average return bar (kid ["homework"]) * .1 + bar (kid ["quizzes"]) * .3 + bar (kid ["tests"]) * .6 students = [Lloyd, Alice, Tyler] def getClassAverage (list): sum = 0 for x in list: sum = sum + getAverage (x) return sum / len (list) print getClassAverage (students)

No comments:

Post a Comment