LabWeek09 (1)

.pdf
School
North Carolina State University**We aren't endorsed by this school
Course
ST 114
Subject
Mathematics
Date
Dec 17, 2024
Pages
3
Uploaded by JudgePartridgeMaster1231
ST 114 Lab Week 9Learning Objectives:Practice with dictionaries.Practice with functions.Problems:1. Write a functionmakegradesdictthat takes in four lists ofthe same length: (1)names, (2)projects, (3)midterms,and (4)finalsand returns a dictionary of dictionaries wherenamesare the keys of outer dictionary and‘project’,‘midterm’,and‘final’are keys of inner dictionaries and theith item inprojects, midterms, and finals are the values in theith inner dic-tionary. For example, suppose we have the following variablesdefined.names = [’Student 1’, ’Student 2’]projects = [94, 89]midterms = [68, 98]finals = [75, 26]Then,makegradesdict(names, projects, midterms,finals)should return{’Student 1’: {’project’: 94,’midterm’: 68,’final’: 751
Background image
},’Student 2’: {’project’: 89,’midterm’: 98,’final’: 26}}2. Write a functionmakegradesstringthat takes in a nesteddictionary with the same structure as the returned value of thefunctionmakegradesdictionary. Your function shouldreturn a formatted string that when printed is displayed as fol-lows.>>> grades = {’Student 1’: {’project’: 94,’midterm’: 68,’final’: 75},’Student 2’: {’project’: 89,’midterm’: 98,’final’: 26}}>>> print(make_grades_string(grades))Student 1:2
Background image
Project: 94Midterm: 68Final: 75-------------------Student 2:Project: 89Midterm: 98Final: 26-------------------Use string formatting using the dictionary keys.3
Background image