SampleTest2023

pdf

School

University of Michigan *

*We aren’t endorsed by this school

Course

106

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

10

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 .upper()? a. int b. float c. string d. list e. bool f. None 2. What is the return type of .join()? a. int b. float c. string d. list e. bool f. None
3. What is the return type of .split()? a. int b. float c. string d. list e. bool f. None 4. What is the return type of .append()? a. int b. float c. string d. list e. bool f. None 5. What is the return type of .readlines()? a. int b. float c. string d. list e. bool f. None 6. What is the return type of .strip()? a. int b. float c. string d. list e. bool f. None
7. What is the return type of .read()? a. int b. float c. string d. list e. bool f. None 8. What type of error is returned in the following code? my_list = [1,2,3,4,5] print(my_List[5]) a. SyntaxError b. NameError c. AttributeError d. TypeError e. KeyError f. AssertionError g. IndexError h. ZeroDivisionError 9. What type of error is returned in the following code? my_list = [1,2,3,4,5] print(my_list.join("!")) a. SyntaxError b. NameError c. AttributeError d. TypeError e. KeyError f. AssertionError g. IndexError h. ZeroDivisionError
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
10.What type of error is returned in the following code? count = 0 total = 0 my_list = [1,2,3,4,5] for element in my_list: total += element avg = total/count a. SyntaxError b. NameError c. AttributeError d. TypeError e. KeyError f. AssertionError g. IndexError h. ZeroDivisionError 11.What type of error is returned in the following code? my_dict = {} print(my_dict[1]) a. SyntaxError b. NameError c. AttributeError d. TypeError e. KeyError f. AssertionError g. IndexError h. ZeroDivisionError
12.What type of error is returned in the following code? total = 0 num_str = "1 # 2 # -34" for num in num_str.split('#'): total += num a. SyntaxError b. NameError c. AttributeError d. TypeError e. KeyError f. AssertionError g. IndexError h. ZeroDivisionError Questions 13 - 17 do not generate errors. Write your answer in the box provided. 13.What is the output of the following code snippet? words = ['a', 'abba', 'bab', 'cab', 'bac', 'abc'] count = 0 for word in words: if word[0] == 'a': count += 1 print(count) 14.What is the output of the following code snippet? words = ['a', 'abba', 'bab', 'cab', 'bac', 'abc'] for word in words: count = 0 if word[0] == 'b': count += 1 print(count)
15.What is the output of the following code snippet? words = ['a', 'abba', 'bab', 'cab', 'bac', 'abc'] for i in range(len(my_list[1])): print(i) 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[-2]) print(adictionary[2]) 17. What is the output of the following code snippet? READ IT CAREFULLY!! words = ['a', 'bbc', 'bab','e'] for word in words: if 'a' or 'e' in word: print(word)
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
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 "SI211" print ( ) 19.# Desired output "Chalmers" print ( ) 20. # Desired output [ ["SI106","SI339"],["SI364"],["SI501","SI538","SI211"]] 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[0] = "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.append("!")
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["a"]= 4 24. Using the dictionary below, write one line of code to print out the value 5 . 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 letters in the ‘input_string’ that are uppercase except if the it is a an uppercase 'O'. (5pts) get_letters ('AeIou') would return ['A', 'I'] get_letters ('ABsSIoX') would return ['A', 'B', 'I', 'X'] get_letters ('sdO') would return []. def get_letters(input_string):
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 get_letters() . They should check that your function returns the correct type and that your function returns the correct value for an empty string, a string with four valid uppercase letters, and a string with three valid uppercase letters.
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
Scratch Paper