SampleExample2023-2

pdf

School

University of Michigan *

*We aren’t endorsed by this school

Course

106

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

8

Uploaded by BailiffStrawMeerkat43

Report
SI106 Exam Fall 2023 Name: ___________________________ Unique name: __________________________ THIS IS A LONG TEST. There are 27 questions and each question is worth 4pts unless noted otherwise in the question. There are a total of 110 points. 90 points is 100%. The max score is 100 points, so you can get some extra credit. Answer the questions as carefully and (when applicable) as concisely as you can. There will be deductions for missing key components in your answer. There will also be deductions if you include information that is not true. WRITE NEATLY IN THE ANSWER BOXES PROVIDED. READ THE QUESTIONS CAREFULLY. If you are unsure about a question, you can write your assumptions to the side but we will not be taking questions during the quiz. 1. What is the return type of .split()? 2. What is the return type of .join()? 3. What is the return type of .isupper()? 4. What is the return type of .append()? 5. What is the return type of .items()?
6. What is the return type of .read()? 7. What is the return type of .readlines()? I am going to list common error types here to help you with Q8-12 SyntaxError, NameError, AttributeError, TypeError, KeyError, AssertionError, IndexError, ZeroDivisionError 8. What type of error is returned in the following code? my_list = [1,2,3,4,5] print(my_list[5]) 9. What type of error is returned in the following code? my_list = [1,2,3,4,5] print(my_list.split("!")) 10.What type of error is returned in the following code? my_list = [1,2,3,4,5] assert len(my_list) == 10 11.What type of error is returned in the following code? my_dict = {} print(my_dict[1]) 12.What type of error is returned in the following code? num_str = "1 # 2 # -34" for num in num_str.split('#'): product *= int(num)
Questions 13 - 17 do not generate errors 13.What is the output of the following code snippet? words = ['the', 'quick', 'brownish', 'fox', 'jumped'] count = 0 for word in words: if len(word) >= 5: count += 1 print(count) 14.What is the output of the following code snippet? words = ['the', 'quick', 'brownish', 'fox', 'jumped'] for word in words: count = 0 if len(word) > 4: count += 1 print(count) 15.What is the output of the following code snippet? my_list = ["cat","dog","fish"] for i in range(len(my_list)): print(i)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
16.What is the output of the following code snippet? alist = ["a", "b", "c", "d"] atuple = (1, 2, 3, "still") adictionary = {1: "all", 2: "b", "b": "c", "all":"still"} print(alist[-1]) print(atuple[0]) print(adictionary[1]) 17. What is the output of the following code snippet? READ IT CAREFULLY!! var1 = 10 var2 = 5 var3 = 10 if var1 < var2 or var3: print("A") elif var2 > var3: print("B") else: print("C") print("Done”)
For questions 18-20, you must use the following code to produce the desired output: courses = {"van Lent":["SI106","SI339"], "Severance":["SI364"], "Chalmers":["SI501","SI538","SI211"]} You can hardcode any of the keys or indices. Example: If the desired output is 3, I would add len(courses) to the print statement. # Desired output 3 print ( len (courses) ) 18.# Desired output "SI339" print ( ) 19.# Desired output "SI538" print ( ) 20. # Desired output " Severance" print ( ) Looking for errors….Make sure to write Yes or No in the answer box. 21. Does this code cause an error? If so, circle the line of code that triggers the error. alist = ["a", "b", "c"] alist[1] = "kicking" 22. Does this code cause an error? If so, circle the line of code that triggers the error. astring = "I'm still doing fine on this exam" astring[-1] = "!"
23. Does this code cause an error? If so, circle the line of code that triggers the error. my_dict = {"a":1, "b":2, "c":3} my_dict["d"]= 4 24. Using the dictionary below, write the code to print out the value 3 . my_dict = {"a":1, "b":2, "c":3} 25. Use the accumulation pattern to finish the function below so that it returns a list of all the positive numbers less than ‘input_val’ that are divisible by 3 or by 5. (Positive numbers are > 0.) (5pts) funky_numbers(25) would return [3,5,6,9,10,12,15,18,20, 21,24] funky_numbers(20) would return [3,5,6,9,10,12,15,18] funky_numbers(2) would return []. def funky_numbers(input_val):
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
26. Finish the function below so that it returns the average value in a list of integers (no strings) in the form numlist = [12, 45, 23, 67]. If the list is empty the function should return -1.0. You are encouraged to use built-in functions, but accumulation patterns work too. (5 pts!) def avg_num(input_list): #Your code here 27. Write four assert statements for avg_num . They should check that your function returns the correct type and that your function returns the correct value for an empty list, a list with 1 number, and a list of 3 unique numbers.
Scratch Paper