4.5.2 Coding Exercise 3 (External resource) (3.0 points possible) Bueller.py Sub
ID: 3707903 • Letter: 4
Question
4.5.2 Coding Exercise 3 (External resource) (3.0 points possible) Bueller.py Submit Run Grades Reset 1 #Write a function called students present. students present 2 #should take as input one parameter, a dictionary. The keys 3 #of the dictionary will be names, and the values will be one 4 #of three strings: "Here", "Present", or an empty string "". 6 #Return a list of the keys for whom the corresponding value 7 #is either "Here" or "Present". 15 18 #Add your code here! 11 def students_present (mydict): present- for name, status in mydict.items(): 14 if status == "Here" or status == "Present": present +=name return status 17 18 #Below are some lines of code that will test your function. 19 #You can change the value of the variable(s) to test your 20 #function with different inputs. 21 # 22 #If your function works correctly, this will originally 23 #print (although the order of the keys may vary): 24 #[ "David", "Marguerite", "Joshua", "Erica"] 25 26 student_list = {"David" : "Here", "Marguerite" : "Here", "Jackie": "", "Joshua": "Present", "Erica": "Here", "Daniel": ""} 29 print (students_present(student_list))Explanation / Answer
def students_present(mydict): lst = [] for key, value in mydict.items(): if value != '': lst.append(key) return lst
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.