Page 1 of 1

Q1-Making Lists (15 points) Below are the results of a hypothetical experiment of measuring the height of a class in a l

Posted: Tue Jul 12, 2022 8:09 am
by answerhappygod
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 1
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 1 (25.14 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 2
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 2 (34.64 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 3
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 3 (22.5 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 4
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 4 (61.88 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 5
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 5 (20.7 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 6
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 6 (48.55 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 7
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 7 (15.45 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 8
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 8 (55.22 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 9
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 9 (33.92 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 10
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 10 (30.1 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 11
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 11 (31.7 KiB) Viewed 59 times
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 12
Q1 Making Lists 15 Points Below Are The Results Of A Hypothetical Experiment Of Measuring The Height Of A Class In A L 12 (29.75 KiB) Viewed 59 times
Q1-Making Lists (15 points) Below are the results of a hypothetical experiment of measuring the height of a class in a land far away: .Katie is 5.6 feet tall . Sarah is 5.4 feet tall Demi is 6.1 feet tall George is 5.8 feet tall John is 5.9 feet tall Create a list called class names and fill it with the names of each person in the class (as strings). Create another list called class heights and fill it with the heights of each person in the class (as floats). Remember that the order of lists and the spelling of the names matter; be sure to keep the order of items the same as listed above and the spelling the same! In 1: YOUR CODE HERE raise NotImplementedError() In 111 Tests for 01 Check both Lists are defined assert isinstance(class_names, list) assert isinstance(class heights, list) In 11 Check both Lists have the same Length, and are of length s assert len(class_names) len(class_heights) 5 In 1: hidden tests/
Q2-Lists of Lists (20 points) You can also make lists that are filled with lists! List-ception. First, create three different lists: . A list called . A list called . A list called boolean list that contains three boolean (can be any booleans) Then, create a new list, called nested list which contains the three lists you created above (in the order specified in the above bullet points). string list that contains three strings (can be any strings) number_list that contains three numbers (can be any numbers - Int or float) In [ ]: # YOUR CODE HERE raise NotImplementedError() In 1: assert isinstance(string list, list). assert len(string list) 3 assert isinstance(string_list[0], str) In 1: assert isinstance(number_list, list) assert len(number_list) 3 assert isinstance(number_list[0], int) or isinstance(number_list[e], float) In [ ]: assert isinstance(boolean_list, list) assert len(boolean_list) #3 assert isinstance(boolean_list[0], bool) In 1: assert isinstance(nested list, list) assert len(nested list) 3 assert isinstance(nested list[e], list)
Part 2: Indexing This part covers indexing lists. In [ ] # For Q3 & Q4, the following lists are provided for you list 1 = [10, 20, 30, 40] list_2 = [13, 15, 17, 19, 21, 23] list 3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] list_4 = [21, 9, 98, 289, 438]
Q3 - Indexing (20 points) Do the following using indexing: . Store the first value in list 1 to index 1 . Store the second value from the end of list 2 to index 2 . Store the first four values of list 3 to index_3 Store the last four values of list 4 to index 4 Note: Values must be stored in the same order they appear in the original list in your output. . In [ ]: # YOUR CODE HERE raise NotImplementedError() In [ ]: assert isinstance(index_1, int) assert index 1 == 10 In [ ]: assert isinstance(index_2, int) assert index_2 == 21 In [ ]: assert isinstance(index_3, list) assert len(index_3) ==4 assert index 3 == [1, 2, 3, 4]
In [ ]: assert isinstance(index_4, list) assert len(index_4) ==4 assert index 4 == [9, 98, 289, 438]
Q4 - Comparisons using Indexing (20 points) Do the following comparisons using indexing: . Check if the second value of list_1 is one of the last three values in list 3 (Hint: remember operator in) . Store the result in comp_result 1 . Check if the third value of list 4 is greater than the fourth value in list_4 . Store the result in comp_result 2 . Check if the last value of list 4 is less than the second value in list_4 . Store the result in comp_result 3 . Check if the second value of list 2 multiplied by the fifth value of list 3 is less than the second to last value in list_4 . Store the result in comp_result 4 Keep in mind that you are storing the result of a comparison to a variable, so resulting variables should all be booleans. In [ ]: # YOUR CODE HERE raise NotImplementedError() In 1: assert isinstance(comp_result_1, bool) assert comp_result 1 False In [ ]: assert isinstance(comp_result 2, bool) assert comp_result 2 == False In [ ]: assert isinstance(comp_result_3, bool) assert comp_result_3= False
In [ ]: assert isinstance (comp_result_4, bool) assert comp_result_4 == True
Part 3: Loops This part covers using loops. Q5-For Loop (5 points) What is the sum of all odd numbers between 30 and 51 (inclusive)? Answer this question using a for loop, and using range. Save the result out to a variable called sum_result. In [] # YOUR CODE HERE raise NotImplementedError() In [ ]: assert isinstance (sum_result, int) assert sum_result == 451
Q6Loops: Multiplication (5 points) Using the provided variable num list, write a for loop to loop across each value, multiplying it by -1. Store the result for each value in a list called eval 1 by defining eval 1 before the loop and using append inside the loop. In [1: # This creates a list of all numbers from 1-12, inclusive num_list = list (range(1, 13)) In [ ]: # YOUR CODE HERE raise NotImplementedError() In [ ]: assert isinstance(eval 1, list). assert isinstance (eval_1[0], int) assert eval_1 == list (reversed (range(-12, 0)))
Part 4: Combining Loops & Conditionals This part covers integrating collections and loops with conditionals and operators. In [ ]: # This List provided to use for the following questions data_list = [-1, 20, -100, -44, 32, 97, -101, 45, -79, 96] Q7 - Loops: Division (5 points) Write some code that uses a loop to find all the values from data list that are perfectly divisible by 4. Use a for loop with a conditional to do this, and save any values from data list that meet this condition into a new list called div 4. In [ ]: # YOUR CODE HERE raise NotImplementedError() div_4 In [ ]: assert isinstance(div 4, list) assert (len (div_4) ==5) assert div 4 == [20, -100, -44, 32, 96]
Q8 - Loops: Odd or Even (5 points) Write a for loop that is going to check whether the values in data list are even or odd. Use a for loop with a conditional to do this. For each value, it should add True to a new list is even if the value is even, and False to is even if the value is odd. In [ ]: # YOUR CODE HERE raise NotImplementedError() is even In ]: assert isinstance(is_even, list) assert (len(is_even) == len(data list)) assert sum(is_even) == 5
Q9-Loops: Multiple Conditions (5 points) Write a for loop that will check each value in data list to see if they are even or odd and whether they are positive or negative. . If they are both positive and even, encode this as the number 1 . If they are both negative and odd, encode this as the number -1 Otherwise, encode this as the number 0 . Store the result for each value into a list called num_type . In []: # YOUR CODE HERE raise NotImplementedError() In []: assert isinstance(num_type, list). assert(len(num_type) e len(data_list)) assert sum([1 for it in nun type if it == 1 ]) 3 assert sum([1 for it in num type if it -1]) == 3 assert sum([1 for it in num type if it == 0 ]) == 4