Top Banner
Python Programming Lab 12
27

Python programming lab12

Aug 07, 2015

Download

Documents

profbnk
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python programming lab12

Python Programming

Lab 12

Page 2: Python programming lab12
Page 3: Python programming lab12
Page 4: Python programming lab12
Page 5: Python programming lab12
Page 6: Python programming lab12
Page 7: Python programming lab12
Page 8: Python programming lab12
Page 9: Python programming lab12
Page 10: Python programming lab12
Page 11: Python programming lab12
Page 12: Python programming lab12
Page 13: Python programming lab12
Page 14: Python programming lab12
Page 15: Python programming lab12
Page 16: Python programming lab12
Page 17: Python programming lab12
Page 18: Python programming lab12

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) return total / len(numbers)

# Get_average functiondef get_average(student): homework = average(student["homework"]) quizzes = average(student["quizzes"]) tests = average(student["tests"]) sum = 0.1 * homework + 0.3 * quizzes + 0.6 * tests return sum

def get_letter_grade(score): if score >= 90: return "A" elif score >= 80: return "B" elif score >= 70: return "C" elif score >= 60: return "D" else: return "F"print get_letter_grade(get_average(lloyd))

B

Page 19: Python programming lab12
Page 20: Python programming lab12
Page 21: Python programming lab12
Page 22: Python programming lab12
Page 23: Python programming lab12
Page 24: Python programming lab12

CODE REVISITED

Page 25: Python programming lab12
Page 26: Python programming lab12
Page 27: Python programming lab12

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) return total / len(numbers)

# Get_average functiondef get_average(student): homework = average(student["homework"]) quizzes = average(student["quizzes"]) tests = average(student["tests"]) sum = 0.1 * homework + 0.3 * quizzes + 0.6 * tests return sum

def get_letter_grade(score): if score >= 90: return "A" elif score >= 80: return "B" elif score >= 70: return "C" elif score >= 60: return "D" else: return "F"# print get_letter_grade(get_average(lloyd))

def get_class_average(students): results = [] for student in students: results.append(get_average(student)) return average(results)

students = [lloyd, alice, tyler]class_average = get_class_average(students)print class_averageprint get_letter_grade(class_average)

83.8666666667 B