Python Programming
Lab 12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
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 function
def 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
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
Python programming lab12
CODE REVISITED
Python programming lab12
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 function
def 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_average
print get_letter_grade(class_average)
83.8666666667
B

More Related Content

PDF
Collections
PPTX
Array,Array Function,Get Method,Post Method
PPTX
Intro to python2
PDF
Swift Study #2
PDF
The Ring programming language version 1.2 book - Part 14 of 84
PDF
A bit about Scala
PDF
Scala for Jedi
PDF
λ | Lenses
Collections
Array,Array Function,Get Method,Post Method
Intro to python2
Swift Study #2
The Ring programming language version 1.2 book - Part 14 of 84
A bit about Scala
Scala for Jedi
λ | Lenses

Similar to Python programming lab12 (20)

PDF
fds Practicle 1to 6 program.pdf
PPTX
Python programming lab 17
DOCX
Practicle 1.docx
PPTX
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
PDF
Program 1 (Practicing an example of function using call by referenc.pdf
PPTX
Python Homework Help
PDF
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
DOCX
#include PA3Header.h#include stdafx.h Function r.docx
PDF
#include stdafx.h#include iostream#include string#incl.pdf
DOCX
cs class 12 project computer science .docx
PPTX
Best of Two Avg, Python Program To Find Average of Two Numbers.pptx
PDF
ayush.pdf
PDF
Python Usage (5-minute-summary)
DOCX
Umid JumayevFinal Lab Examimport java.util.Scanner; i.docx
PDF
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
PPTX
File Programs with Solutions on python.pptx
PDF
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
PDF
Python for High School Programmers
PPTX
Python Statistics.pptx
DOCX
PROG.docx
fds Practicle 1to 6 program.pdf
Python programming lab 17
Practicle 1.docx
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Program 1 (Practicing an example of function using call by referenc.pdf
Python Homework Help
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
#include PA3Header.h#include stdafx.h Function r.docx
#include stdafx.h#include iostream#include string#incl.pdf
cs class 12 project computer science .docx
Best of Two Avg, Python Program To Find Average of Two Numbers.pptx
ayush.pdf
Python Usage (5-minute-summary)
Umid JumayevFinal Lab Examimport java.util.Scanner; i.docx
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
File Programs with Solutions on python.pptx
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Python for High School Programmers
Python Statistics.pptx
PROG.docx
Ad

More from profbnk (20)

PPTX
JavaServer Pages
PPTX
Java swing
PPTX
Java Virtual Machine
PPTX
Big data2.0.040915
PDF
Big data
PPTX
Python programming advance lab api we pay
PPTX
Python programming advance lab api how to
PPTX
Python programming advance lab api npr 2
PPTX
Python programming lab 20
PPTX
Python programming lab 19
PPTX
Python programming lab 18
PPTX
Python programming lab 23
PPTX
Python programming21
PPTX
Python programming lab16
PPTX
Python programming lab15
PPTX
Python programming lab14
PPTX
Python programming lab13
PPTX
Python programming lab 11
PPTX
Python programming lab 10
PPTX
Python programming lab 9
JavaServer Pages
Java swing
Java Virtual Machine
Big data2.0.040915
Big data
Python programming advance lab api we pay
Python programming advance lab api how to
Python programming advance lab api npr 2
Python programming lab 20
Python programming lab 19
Python programming lab 18
Python programming lab 23
Python programming21
Python programming lab16
Python programming lab15
Python programming lab14
Python programming lab13
Python programming lab 11
Python programming lab 10
Python programming lab 9
Ad

Python programming lab12

  • 18. 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 function def 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
  • 27. 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 function def 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_average print get_letter_grade(class_average) 83.8666666667 B