Python Data Representations Week1

docx

School

Grand Rapids Community College *

*We aren’t endorsed by this school

Course

117

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

3

Uploaded by ConstableWildcatMaster401

Report
Congratulations! You passed! Grade received 71.42% Latest Submission Grade 71.43% To pass 70% or higher Go to next item 1. Question 1 Which of the following expressions evaluates to the list [0, 1, 2, 3, 4, 5] [0, 1, 2, 3, 4, 5] ? 0 / 1 point list(range(6)) list(range(6)) list(range(0, 5, 1)) list(range(0, 5, 1)) list(range(0, 6)) list(range(0, 6)) Correct This expression returns the list [0, 1, 2, 3, 4, 5] [0, 1, 2, 3, 4, 5] . range(6) range(6) You didn’t select all the correct answers 2. Question 2 Let my_list my_list be the list ["This", "course", "is", "great"] ["This", "course", "is", "great"] . What is len(my_list) len(my_list) ? What non-negative number is the index of "great" "great" ? I.e., how would you replace the question marks in my_list[???] my_list[???] so that the resulting value is "great" "great" ? Submit two numbers, one for each of these two questions, separated by spaces. 0 / 1 point 43 Incorrect Remember that the question specifies that both of the entered numbers should be non-negative. 3. Question 3 If we want to split a list my_list my_list into two halves, which of the following uses slices to do so correctly? More precisely, if the length of my_list my_list is 2n, i.e., even, then the two parts should each have length n. If its length is 2n+1, i.e., odd, then the two parts should have lengths n and n+1. 1 / 1 point my_list[0 : len(my_list) // 2 - 1] my_list[0 : len(my_list) // 2 - 1] and my_list[len(my_list) // 2 : len(my_list)] my_list[len(my_list) // 2 : len(my_list)] my_list[0 : len(my_list) // 2] my_list[0 : len(my_list) // 2] and my_list[len(my_list) // 2 + 1 : len(my_list)] my_list[len(my_list) // 2 + 1 : len(my_lis t)] my_list[0 : len(my_list) // 2] my_list[0 : len(my_list) // 2] and my_list[len(my_list) // 2 : len(my_list)] my_list[len(my_list) // 2 : len(my_list)] Correct my_list[: len(my_list) // 2] my_list[: len(my_list) // 2] and my_list[len(my_list) // 2 :] my_list[len(my_list) // 2 :]
Correct 4. Question 4 If n and m are non-negative integers, consider the list final_list final_list computed by the code snippet below. 1 2 init_list = list ( range ( 1 , n)) final_list = init_list * m The length of this list depends on the particular values of n and m used in computation. Which option below correctly expresses the length of final_list final_list in terms of n and m ? 1 / 1 point + � � n + m × � � n × m ×( −1) n ×( m −1) ( −1)× ( n −1)× m Correct 5. Question 5 If n is a non-negative integer, consider the list split_list split_list computed by the code snippet below. 1 2 test_string = "xxx" + " " * n + "xxx" split_list = test_string.split( " " ) The length of this list depends on the particular values of n used in computation. Which option below correctly expresses the length of split_list split_list in terms of n ? 1 / 1 point 22 n +1 n +1 33 Correct 6. Question 6 Select the code snippets below in which list2 list2 is a copy of list list1 list1 (as opposed to simply being another reference to the list list1 list1 ). 1 / 1 point 1 2 list1 = list ( range ( 1 , 10 )) list2 = list1[:] Correct This code snippet makes a copy. Try modifying list2 list2 and seeing if list1 list1 is mutated.
1 2 list1 = list ( range ( 1 , 10 )) list2 = list (list1) Correct This code snippet makes a copy. Try modifying list2 list2 and seeing if list1 list1 is mutated. 1 2 list1 = list ( range ( 1 , 10 )) list2 = [] + list1 Correct This code snippet makes a copy. Try modifying list2 list2 and seeing if list1 list1 is mutated. 1 2 list1 = list ( range ( 1 , 10 )) list2 = list1 7. Question 7 Write a function strange_sum(numbers) strange_sum(numbers) that takes a list of integers and returns the sum of those items in the list that are not divisible by 33 . When you are done, test your function using the code snippet below. 1 2 print (strange_sum([ 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 , 4 , 5 ])) print (strange_sum( list ( range ( 123 )) + list ( range ( 77 )))) The first line in the test should print the number 24 24 in the console. Enter the second number printed in the console in the box below. 1 / 1 point 6994 Correct
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