week 3 chaggenge course lesson number one

Make a gradebook for all of your students.

1.创建3个字典

lloyd={"name":"Lloyd","homework":[],"quizzes":[],"tests":[]}

alice={"name":"Alice","homework":[],"quizzes":[],"tests":[]}

tyler={"name":"Tyler","homework":[],"quizzes":[],"tests":[]}

2.填入score

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]

}

3.创建一个学生list

students=[lloyd,alice,tyler]

4.输出每个学生的成绩

for i in range(0,3):

  sample=students[i]

  print sample["name"]

  print sample["homework"]

  print sample["quizzes"]

  print sample["tests"]

5.It's Okay to be Average

def average(numbers):

  total=float(sum(numbers))

  return total/len(numbers)

6.得到加权平均数

def get_average(student):

  homework=average(student["homework"])

  quizzes=average(student["quizzes"])

  tests=average(student["tests"])

  weighted_average=0.1*homework+0.3*quizzes+0.6*tests

  return weighted_average

7.get letter and test

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))

8.得到班级平均数

def get_class_average(class_list):

  results=[]

  for i in class_list:

    result=get_average(i)

    results.append(result)

  return average(results)

9.

你可能感兴趣的:(week 3 chaggenge course lesson number one)