[codecademy] 6. Student Becomes the Teacher
Student Becomes the Teacher
Student Becomes the Teacher 1/9
Lesson Number One
챌린지 코스 1번째!!
참고코드
문제
1. Create three dictionaries: lloyd, alice, and tyler.
2. Give each dictionary the keys "name", "homework", "quizzes", and "tests".
3. Have the "name" key be the name of the student (that is, lloyd's name should be "Lloyd") and the other keys should be an empty list. (We'll fill in these lists soon!)
Student Becomes the Teacher 2/9
What's the Score?
잘했어요!
문제
Now fill out your lloyd dictionary with the appropriate scores. To save you some time, we've filled out the rest for you.
Homework: 90.0, 97.0, 75.0, 92.0
Quizzes: 88.0, 40.0, 94.0
Test Scores: 75.0, 90.0
Make sure to include the decimal points so your grades are stored as floats! This will be important later.
Student Becomes the Teacher 3/9
Put It Together
세개의 딕셔너리를 하나의 리스트로 모아보자.
참고 코드
문제
Below your code, create a list called students that contains lloyd, alice, and tyler.
Student Becomes the Teacher 4/9
For the Record
잘했어요!
참고 코드
문제
for each student in your students list, print out that student's data, as follows:
1. print the student's name
2. print the student's homework
3. print the student's quizzes
4. print the student's tests
Student Becomes the Teacher 5/9
It's Okay to be Average
설명없음!
참고 코드
문제
Write a function average that takes a list of numbers and returns the average.
1. Define a function called average that has one argument, numbers.
2. Inside that function, call the built-in sum() function with the numbers list as a parameter. Store the result in a variable called total.
3. Like the example above, use float() to convert total and store the result in total.
4. Divide total by the length of the numbers list. Use the built-in len() function to calculate that.
5. Return that result.
Student Becomes the Teacher 6/9
Just Weight and See
참고코드
문제
Write a function called get_average that takes a student dictionary (like lloyd, alice, or tyler) as input and returns his/her weighted average.
1. Define a function called get_average that takes one argument called student.
2. Make a variable homework that stores the average() of student["homework"].
3. Repeat step 2 for "quizzes" and "tests".
4. Multiply the 3 averages by their weights and return the sum of those three. Homework is 10%, quizzes are 30% and tests are 60%.
Student Becomes the Teacher 7/9
Sending a Letter
잘했어요!
문제
1. Define a new function called get_letter_grade that has one argument called score. Expect score to be a number.
2. Inside your function, test score using a chain of if: / elif: / else: statements, like so:
If score is 90 or above: return "A"
Else if score is 80 or above: return "B"
Else if score is 70 or above: return "C"
Else if score is 60 or above: return "D"
Otherwise: return "F"
3. Finally, test your function! Call your get_letter_grade function with the result of get_average(lloyd). Print the resulting letter grade.
Student Becomes the Teacher 8/9
Part of the Whole
Good! 이제 반평균을 계산해보자
1. Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students.
2. First, make an empty list called results.
3. For each student item in the class list, calculate get_average(student) and then call results.append() with that result.
4. Finally, return the result of calling average() with results.
Student Becomes the Teacher 9/9
How is Everybody Doing?
잘했어요!
문제
Finally, print out the result of calling get_class_average with your students list. Your students should be [lloyd, alice, tyler].
Then, print the result of get_letter_grade for the class's average.
'프로그래밍 > Python' 카테고리의 다른 글
[codecademy] 7.LISTS AND FUNCTIONS (317) | 2015.11.07 |
---|---|
[codecademy] 4. FUNCTIONS (314) | 2015.09.05 |
[codecademy] 5.LISTS & DICTIONARIES (319) | 2015.08.28 |
[codecademy] 3.CONDITIONALS AND CONTROL FLOW (301) | 2015.08.10 |
Python 시리얼 출력(serial 통신) (4) | 2015.07.24 |