Skip to content

Commit 9e3ff35

Browse files
Initial commit
0 parents  commit 9e3ff35

17 files changed

+702
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
.idea/
3+
*.iml
4+
.vscode
5+
__pycache__
6+
*pyc
7+
*.ipynb_checkpoints
8+
venv/

exam1/README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
## Exercise 1
2+
3+
Open the program called *converter.py*
4+
5+
* Remove the line containing the pass statement and implement the functionality described in the docstring.
6+
* Run the unit tests to validate that the implementation passes unit tests.
7+
8+
```
9+
python3 -m unittest exam1.test_converter
10+
```
11+
12+
## Exercise 2
13+
14+
Open the program called *evaluator.py*
15+
16+
* Remove the line containing the pass statement and implement the functionality described in the docstring.
17+
* Run the unit tests to validate that the implementation passes unit tests.
18+
19+
```
20+
python3 -m unittest exam1.test_evaluator
21+
```
22+
23+
## Exercise 3
24+
25+
[Leap years](https://www.timeanddate.com/date/leapyear.html) are years where an extra day is added to the end of
26+
the month of February.
27+
28+
Criteria to identify a leap year:
29+
* The year must be evenly divisible by 4;
30+
* If the year can also be evenly divided by 100, it is not a leap year; unless
31+
* The year is also evenly divisible by 400. Then it is a leap year.
32+
33+
Open the program called *gregorian_cal_utils.py*
34+
35+
* Remove the line containing the pass statement and implement the functionality described in the docstring.
36+
* Run the unit tests to validate that the implementation passes unit tests.
37+
38+
```
39+
python3 -m unittest exam1.test_gregorian_cal_utils
40+
```
41+
42+
## Exercise 4
43+
44+
Open the program called *loopty_loop.py*
45+
46+
* Remove the line containing the pass statement and implement the functionality described in the docstring.
47+
* Run the unit tests to validate that the implementation passes unit tests.
48+
49+
```
50+
python3 -m unittest exam1.test_loopty_loop
51+
```
52+
53+
## Exercise 5
54+
55+
Open the program called *listies.py*
56+
57+
* Remove the line containing the pass statement and implement the functionality described in the docstring.
58+
* Run the unit tests to validate that the implementation passes unit tests.
59+
60+
```
61+
python3 -m unittest exam1.test_listies
62+
```
63+
64+
## Exercise 6
65+
66+
Open the program called *dictionaries.py*
67+
68+
* Remove the line containing the pass statement and implement the functionality described in the docstring.
69+
* Run the unit tests to validate that the implementation passes unit tests.
70+
71+
```
72+
python3 -m unittest exam1.test_dictionaries
73+
```
74+

exam1/__init__.py

Whitespace-only changes.

exam1/cases.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# cases
2+
'''
3+
In some languages, it’s common to use camel case (otherwise known as “mixed case”) for variables’
4+
names when those names comprise multiple words, whereby the first letter of the first word is
5+
lowercase but the first letter of each subsequent word is uppercase. For instance, whereas a variable
6+
for a user’s name might be called name, a variable for a user’s first name might be called firstName, and a variable for a user’s preferred first name (e.g., nickname) might be called preferredFirstName.
7+
8+
Python, by contrast, recommends snake case, whereby words are instead separated by underscores (_),
9+
with all letters in lowercase. For instance, those same variables would be called name, first_name,
10+
and preferred_first_name, respectively, in Python.
11+
12+
In a file called cases.py, implement a function called camel2snake() that takes the name of a
13+
variable in camel case and outputs the corresponding name in snake case.
14+
Assume that the user’s input will indeed be in camel case.
15+
'''
16+
17+
18+
'''
19+
Now make one that does the opposite: snake2camel()
20+
'''
21+
22+
23+
def foo():
24+
pass

exam1/converter.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
def meters_to_feet(meters: float) -> float:
2+
"""
3+
This function takes a float representing a measurement in meters
4+
and returns the corresponding value converted to feet.
5+
The result is rounded to 2 decimal places.
6+
7+
:param meters: A float representing a measurement in meters.
8+
:return: A float representing the input measurement converted to feet.
9+
"""
10+
pass # implement me
11+
12+
13+
def feet_to_meters(feet: float) -> float:
14+
"""
15+
This function takes a float representing a measurement in feet
16+
and returns the corresponding value converted to meters.
17+
The result is rounded to 2 decimal places.
18+
19+
:param feet: A float representing a measurement in feet.
20+
:return: A float representing the input measurement converted to meters.
21+
"""
22+
pass # implement me
23+
24+
25+
def kilometer_to_miles(kilometers: float) -> float:
26+
"""
27+
This function takes a float representing a measurement in kilometers
28+
and returns the corresponding value converted to miles.
29+
The result is rounded to 2 decimal places.
30+
31+
:param kilometers: A float representing a measurement in kilometers.
32+
:return: A float representing the input measurement converted to miles.
33+
"""
34+
pass # implement me
35+
36+
37+
def miles_to_kilometers(miles: float) -> float:
38+
"""
39+
This function takes a float representing a measurement in miles
40+
and returns the corresponding value converted to kilometers.
41+
The result is rounded to 2 decimal places.
42+
43+
:param miles: A float representing a measurement in miles.
44+
:return: A float representing the input measurement converted to kilometers.
45+
"""
46+
pass # implement me
47+
48+

exam1/dictionaries.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
def delete_keys_from_dict(datadict, keylist):
3+
"""
4+
Delete a list of keys from a dictionary
5+
"""
6+
pass
7+
8+
def check_dict_for_key(datadict, key):
9+
"""
10+
Check if a value exists in a dictionary
11+
(NO FOR loops!)
12+
"""
13+
pass
14+
15+
def get_key_of_min_value(ddd):
16+
"""
17+
Get the key of the minimum value from a dictionary
18+
"""
19+
pass
20+
21+
def get_key_of_max_value(ddd):
22+
"""
23+
Get the key of the maximum value from a dictionary
24+
"""
25+
pass
26+
27+
def letterfreq(word):
28+
'''
29+
# Write a function that returns a dictionary of letter frequencies from a word
30+
'''
31+
pass

exam1/evaluator.py

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from typing import List, Tuple, Set, TypeVar
2+
3+
N = TypeVar('N', int, float)
4+
C = TypeVar('C', List, Tuple)
5+
6+
7+
def find_lowest_value(list_in: List[N]) -> N:
8+
"""
9+
Returns the lowest value in a list of numbers.
10+
11+
:param list_in: A list of numbers (integers and/or floats)
12+
:return: The lowest number in the list
13+
"""
14+
pass # implement me
15+
16+
17+
def find_highest_value(list_in: List[N]) -> N:
18+
"""
19+
Returns the highest value in a list of numbers.
20+
21+
:param list_in: A list of numbers (integers and/or floats)
22+
:return: The highest number in the list
23+
"""
24+
pass # implement me
25+
26+
27+
def find_value(value_to_find, values: C) -> int:
28+
"""
29+
This function evaluates whether a value exists within a List or a Set.
30+
If the value exists, the function returns the index of the value in the collection.
31+
If the value does not exist, the function returns -1.
32+
33+
:param value_to_find: A value that may or may not exist within a collection.
34+
:param values: A List or a Set.
35+
:return: an integer. Either the index where the value exists or -1
36+
"""
37+
pass # implement me
38+
39+
40+
def compare_two_numbers(a: N, b: N) -> int:
41+
"""
42+
Compares two numbers.
43+
44+
If the numbers are the same, this function will return the number 0.
45+
If the first number is greater than the second, this function will return the number 1.
46+
If the second number is greater than the second, this function will return the number -1.
47+
48+
:param a: The first number.
49+
:param b: The second number.
50+
:return: an integer 0, 1, or -1
51+
"""
52+
pass # implement me
53+
54+
55+
def compare_two_strings(a: str, b: str) -> int:
56+
"""
57+
Compares two strings.
58+
59+
If the strings have the same length, this function will return the number 0.
60+
If the first string is longer than the second string, this function will return the number 1.
61+
If the second string is longer than the first string, this function will return the number -1.
62+
63+
:param a: The first string.
64+
:param b: The second string.
65+
:return: an integer 0, 1, or -1
66+
"""
67+
pass # implement me
68+
69+
70+
def find_common(tuple_a: Tuple, tuple_b: Tuple) -> Set:
71+
"""
72+
Given two tuples, this function returns a set containing items common in both tuples.
73+
74+
:param tuple_a: The first tuple.
75+
:param tuple_b: The second tuple.
76+
:return: A set containing items common on both tuples.
77+
"""
78+
pass # implement me
79+
80+
81+
def find_duplicates(tuple_in: Tuple) -> List:
82+
"""
83+
Given a tuple, this function returns a list of the items that contain more than one instance.
84+
85+
:param tuple_in: A tuple
86+
:return: a A list containing duplicate items in the tuple_in parameter
87+
"""
88+
pass # implement me

exam1/gregorian_cal_utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def is_leap_year(year: int) -> bool:
2+
"""
3+
Given a year, this function returns a boolean indicating whether or not it is a leap year.
4+
5+
:param year: an integer indicating a year.
6+
:return: A boolean indicating whether or not the year parameter is a leap year.
7+
"""
8+
pass # implement me

exam1/listies.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
def drop_last(lst):
3+
"""
4+
This function takes a list and returns a list with the last item removed.
5+
"""
6+
pass # implement me
7+
8+
def drop_mangle(lst):
9+
"""
10+
This function takes a list and returns a list with the first two items AND last item removed.
11+
"""
12+
pass # implement me
13+
14+
def add_item_front(lst, a):
15+
"""
16+
This function takes a list and an item,
17+
returning the list with the item prepended to the list
18+
"""
19+
pass # implement me
20+
21+
def add_item_end(lst, a):
22+
"""
23+
This function takes a list and an item,
24+
returning the list with the item appended to the list
25+
"""
26+
pass # implement me
27+
28+
def drop_first_two(lst):
29+
"""
30+
This function takes a list and returns a list with the first two items removed.
31+
"""
32+
pass # implement me
33+
34+
def drop_last_two(lst):
35+
"""
36+
This function takes a list and returns a list with the last two items removed.
37+
"""
38+
pass # implement me
39+

exam1/loopty_loop.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import Callable, List
2+
3+
4+
def generate_list(start: int, stop: int, step: int = 1) -> List[int]:
5+
"""
6+
Generate a list of integers.
7+
8+
:param start: Where to start the list (inclusive).
9+
:param stop: Where to stop the list (exclusive).
10+
:param step: How many digits apart each number is from the others around it.
11+
:return: A list of integers.
12+
"""
13+
pass # implement me
14+
15+
16+
def generate_list_with_strategy(start: int, stop: int, step: int, strategy: Callable) -> List[int]:
17+
"""
18+
Generate a list of integers.
19+
20+
:param start: Where to start the list (inclusive).
21+
:param stop: Where to stop the list (exclusive).
22+
:param step: How many digits apart each number is from the others around it.
23+
:param strategy: A function to manipulate each digit .
24+
:return: A list of integers.
25+
"""
26+
pass # implement me

0 commit comments

Comments
 (0)