# Python Warmup Assignment
|
Solve the following problems in Python 3.6+ . In addition to making sure that your code gives the correct solution, each solution must meet the following conditions. |
|
1. Your function parameters must be [type- hinted](https://docs.python.org/3.6/library/typing.html]). These need not be perfect, but should be generally correctly describe your input and output. Here is an example of what your code should look like. For example ```python from typing import List def average(num_list: List[int]) -> float: “””Finds the average of a list of numbers. doctests:
>>> average([1,2,3,4,5])
3.0
>>> average([0])
0.0
"""
|
list_sum = sum(num_list)
list_size = len(num_list)
avg = list_sum/list_size
return avg
if __name__ == "__main__":
import doctest
doctest.testmod() ``` ## Problem 1 |
``` Input: "abc" Output: ['a','b','c'] ``` ## Problem 2 ## Problem 3 |
``` Input: 5 Output: [5,2,3,1,5] ``` ## Problem 4 ``` Input: [1,2,3,4,5] Output: [5,4,3,2,1] ``` ## Problem 5 ```
Input: [1,1,3,2,3,2,3,2,2]
Output: {1: 2, 3: 3, 2: 4}
```
## Problem 6 ```
Input: [1,1,3,2,3,2,3,2,2]
Output: {1,2,3}
|
|
“` ## Problem 7 ``` Input: [1,2,3,4,5,1,2] Output: 1 ``` ## Problem 8 |
|
Write a function that takes an integer n and output a `dict` containing keys from 0,2 … to n and each key is mapped to a list containing the square and cube of the number. ```
Input: 3
Output:
{
0:[0,0],
1:[1,1],
2:[4,8],
3:[9,27]
} “` |
|
## Problem 9 “` ## Problem 10 ``` Input : 5 Output : [0, 1, 4, 9, 16, 25] ``` ## Problem 11 “` ## Problem 12. Write a `class` such that : |
|
1. The initializer takes an arbitrary list of atomic values as input and saves it in a instance variable. 1. Accepts a function as a parameter. You can use a lambda function. 2. Applies the function to saved list and return the output. The instance variable must not be modified. 3. If it fails `raise` an `Exception` with a custom error message. You can use `try` and `except` here. ```python def sq(x): return x**2 |
c1 = MyClass([1,2,3,4]) print(c1.apply(lambda x:x**2)) [1,4,9,16] c2 = MyClass([‘a’,’b’,’c’]) Traceback (most recent call |
|
“` ## Problem 13 ``` Input : ['aa','bb','cd','e'] Output : ['AA', 'BB', 'CD', 'E'] ``` ## Problem 14: ``` Input : [1,2,3,4,5] Output : 120 ``` |


