diff --git a/Intro/responses.txt b/Intro/responses.txt index 8b13789..ec52f2f 100644 --- a/Intro/responses.txt +++ b/Intro/responses.txt @@ -1 +1 @@ - +My name is Kachi. I'm so excited for comp. diff --git a/Python/random_ints.py b/Python/random_ints.py new file mode 100644 index 0000000..cb770d0 --- /dev/null +++ b/Python/random_ints.py @@ -0,0 +1,25 @@ +import random + +def random_ints(): + ans = [] + while True: + n = random.randint(1, 10) + ans.append(n) + if n == 6: + return ans + + +def test(): + N = 10000 + total_length = 0 + for i in range(N): + l = random_ints() + assert not 0 in l + assert not 11 in l + assert l[-1] == 6 + total_length += len(l) + assert abs(total_length / N - 10) < 1 # checks that the length of the random strings are reasonable. + print("Success!") + +if __name__ == "__main__": + test() diff --git a/Python/rm_smallest.py b/Python/rm_smallest.py new file mode 100644 index 0000000..08fffea --- /dev/null +++ b/Python/rm_smallest.py @@ -0,0 +1,28 @@ +def rm_smallest(d): + ans = d + length = len(ans) + keys = list(ans) + if length == 0 or length == 1: + return {} + else: + lst = list(ans.values()) + min = lst[0] + index = 0 + for i in range(len(lst)): + if lst[i] < min: + min = lst[i] + index = i + del ans[keys[index]] + print(ans) + return ans + + +def test(): + assert 'a' in rm_smallest({'a':1,'b':-10}).keys() + assert not 'b' in rm_smallest({'a':1,'b':-10}).keys() + assert not 'a' in rm_smallest({'a':1,'b':5,'c':3}).keys() + rm_smallest({}) + print("Success!") + +if __name__ == "__main__": + test() \ No newline at end of file diff --git a/Python/square_root.py b/Python/square_root.py new file mode 100644 index 0000000..d1ed1ac --- /dev/null +++ b/Python/square_root.py @@ -0,0 +1,17 @@ +import math + +def square_root(n): + if not str(n).isdigit(): + return -1 + else: + return math.sqrt(n) + +def test(): + assert square_root(4) == 2 + assert square_root(0) == 0 + assert square_root("hello") == -1 + assert square_root(-10) == -1 + print("Success!") + +if __name__ == "__main__": + test() \ No newline at end of file diff --git a/Python/sum.py b/Python/sum.py new file mode 100644 index 0000000..1b49c27 --- /dev/null +++ b/Python/sum.py @@ -0,0 +1,15 @@ +def sum(lst, n): + ans = 0 + for i in lst: + ans += i + + return ans == n + +def test(): + assert sum([-1, 1], 0) + assert not sum([0,2,3], 4) + assert sum([0,2,2], 4) + print("Success!") + +if __name__ == "__main__": + test() \ No newline at end of file