Question

In: Computer Science

Using a Python environment of your choice – Create the following three dictionaries: Gary, Alice, and...

Using a Python environment of your choice –

  1. Create the following three dictionaries: Gary, Alice, and Tyler

Gary = {

"name": "Gary",

"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]

}

  • Insert one additional (new) dictionary of your choice
  • Create a new list named students that contains four dictionary items
  • for each student in your students list, print out that student's data, as follows:
    • print the student's name
    • print the student's homework
    • print the student's quizzes
    • print the student's tests
  • Write a function average that takes a list of numbers and returns the average
    • Define a function called average that has one argument, numbers
    • Inside that function, call the built-in sum() function with the numbers list as a parameter. Store the result in a variable called total
    • Use float() to convert total and store the result in total
    • Divide total by the length of the numbers list. Use the built-in len() function to calculate that
    • Return that result
  • Write a function called get_average that takes a student dictionary (like lloyd, alice, or tyler) as input and returns his/her weighted average.
    • Define a function called get_average that takes one argument called student.
    • Make a variable homework that stores the average() of student["homework"].
    • Repeat step 2 for "quizzes" and "tests".
    • Multiply the 3 averages by their weights and return the sum of those three. Homework is 10%, quizzes are 30% and tests are 60%.
  • Define a function called get_class_average that has one argument, students. You can expect students to be a list containing your three students.
    • First, make an empty list called results.
    • For each student item in the class list, calculate get_average(student) and then call results.append() with that result.
    • Finally, return the result of calling average() with results.
  • Finally, print out the result of calling get_class_average with the students list.

Solutions

Expert Solution

Thanks for the question.

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please rate the answer. 
Thanks!

===========================================================================

# Write a function average that takes a list of numbers and returns the ave
def average(lst):
    return float(sum(lst)) / len(lst)


# Write a function called get_average that takes a student dictionary
def get_average(dict):
    homework_average = average(dict['homework'])
    quizzes_average = average(dict['quizzes'])
    test_average = average(dict['tests'])
    return 0.1 * homework_average + 0.3 * quizzes_average + 0.6 * test_average


# Define a function called get_class_average that has one argument, students.
# You can expect students to be a list containing your three students.
def get_class_average(students_list):
    # First, make an empty list called results.
    results = []
    for student in student_list:
        results.append(get_average(student))
    return average(results)


Gary = {"name": "Gary", "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]}
# Insert one additional (new) dictionary of your choice
Marsha = {"name": "Marsha", "homework": [90.0, 77.0, 68.0, 72.0], "quizzes": [6.0, 69.0, 74.0], "tests": [78.0, 80.0]}
# Create a new list named students that contains four dictionary items
student_list = [Gary, Alice, Tyler, Marsha]
# for each student in your students list, print out that student's data, as follows
for student in student_list:
    print('Student Name: {}'.format(student['name']))
    print('Homework Scores: {}'.format(' '.join([str(score) for score in student['homework']])))
    print('Quizzes Scores: {}'.format(' '.join([str(score) for score in student['quizzes']])))
    print('Test Scores: {}\n'.format(' '.join([str(score) for score in student['tests']])))

# Finally, print out the result of calling get_class_average with the students list.
print('Class Average: {:.2f}'.format(get_class_average(student_list)))

=======================================================================


Related Solutions

Using a Python environment of your choice – Create the following three dictionaries: Gary, Alice, and...
Using a Python environment of your choice – Create the following three dictionaries: Gary, Alice, and Tyler Gary = { "name": "Gary", "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] } Insert one additional (new) dictionary of your choice Create a new list named students that...
Create three Python examples using the following patterns: Factory, Facade, and Singleton.
Create three Python examples using the following patterns: Factory, Facade, and Singleton.
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: g. def big_words(text, min_length=10): """ Return a list of big words whose length is at least min_length """ return [] h. def common_words(text, min_frequency=10): """ Return words occurring at...
Create a game of your choice that involves the following concepts:
C++ PROJECTCreate a game of your choice that involves the following concepts:STL library. (Maps, Sets, Lists, Stacks and Queues), with Iterators and AlgorithmsShow especially Especially Algorithm/Iterators/Containers in the STLMinimum of 750 linesInclude Full documentation
Using Python, Establish random centroids according to the k , and create your own algorithm to...
Using Python, Establish random centroids according to the k , and create your own algorithm to make clusters: create a functions kmeans() that accepts a dataframe and k as parameters, and returns the clusters created.
Bob has offered Alice the choice between the following two options:
Bob has offered Alice the choice between the following two options:Option A) Receive $10,000 in one year from today OptionB) Receive $500 every year starting one year from todayThe interest rate is fixed at 5%. Alice wants to choose the option with the higher present value. Calculate the present value for each option and determine which option should she choose?
Create a emergency pandemic plan for the sports franchise of your choice using the text CHs...
Create a emergency pandemic plan for the sports franchise of your choice using the text CHs that we have gone over to outline your plan.
(20 pts) Using your programming language of choice (from C++, Java, or Python) , also drawing...
(20 pts) Using your programming language of choice (from C++, Java, or Python) , also drawing on your experience from program 1, read an integer, n from keyboard (standard input). This integer represents the number of integers under consideration. After reading that initial integer in, read n integers in, and print the minimum and maximum of all the integers that are read in. Example: Input Output 7 1 5 3 6 9 22 2 Min: 1 Max: 22 C++ preferred
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT