ubuntu2004
Kernel: Python 3 (system-wide)
COSC 130 - Homework 02
Kyle Anderson
Problem 1: Altering Lists
In [1]:
Out[1]:
['Beth', 'Gina', 'Drew', 'Emma', 'Alex', 'Herb', 'Chad', 'Iris']
[15, 12, 8, 6, 5, 3, 2, 0]
Problem 2: Sorting and Slicing Lists
In [2]:
Out[2]:
Length of random_list: 99
First 10 elements of random_list: [242, 137, 336, 270, 341, 179, 73, 195, 5, 191]
The sum of the elements in random list is 23739
First 10 elements of sorted_list: [0, 5, 9, 15, 26, 30, 31, 38, 42, 44]
First 10 elements of random_list: [0, 5, 9, 15, 26, 30, 31, 38, 42, 44]
The smallest element of bot_slice is 0
The largest element of bot_slice is 173
The smallest element of mid_slice is 179
The largest element of mid_slice is 318
The smallest element of top_slice is 319
The largest element of top_slice is 484
Problem 3: Magnitude of a Vector
In [3]:
Out[3]:
magnitude of vector = 20.3715
rounded_unit_vector: [0.54, 0.2945, -0.3927, 0.1964, -0.6381, 0.1473]
magnitude of unit vector = 1.000000
Problem 4: Fibonacci Sequence
In [4]:
Out[4]:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229]
Problem 5: Printing a Table
In [5]:
Out[5]:
First Last Major Credits GPA
--------------------------------------------------------
Anna Anderson Mathematics 110 3.56
Beatrice Brown Data Science 83 3.24
Charles Clark Biology 64 3.87
David Daniels Chemistry 35 2.83
Emma Edwards Computer Science 104 3.61
Problem 6: Calculating Sum of Squared Errors
In [6]:
Out[6]:
[8.419999999999998, 8.239999999999998, 10.280000000000001, 7.579999999999999, 6.86, 8.059999999999999, 7.46, 9.98, 10.939999999999998, 10.939999999999998, 8.599999999999998, 9.079999999999998, 10.52, 7.039999999999998, 8.599999999999998, 7.939999999999999, 8.899999999999999, 11.48, 9.98, 10.34]
Sum of Squared Errors(SSE)= 10.2236
Problem 7: Determining Monthly Payments
In [7]:
Out[7]:
A loan of $200000 would require monthly payments of $80000.0
Problem 8: Adding Matrices
In [8]:
Out[8]:
A
[13, 43, 28, 22, 41]
[17, 39, 46, 16, 21]
[41, 34, 31, 25, 14]
B
[35, 29, 43, 21, 31]
[48, 26, 19, 17, 23]
[32, 34, 24, 16, 27]
AplusB
[48, 72, 71, 43, 72]
[65, 65, 65, 33, 44]
[73, 68, 55, 41, 41]