Skip to content

Submit. #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Intro/responses.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

My name is Kachi. I'm so excited for comp.
25 changes: 25 additions & 0 deletions Python/random_ints.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions Python/rm_smallest.py
Original file line number Diff line number Diff line change
@@ -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()
17 changes: 17 additions & 0 deletions Python/square_root.py
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 15 additions & 0 deletions Python/sum.py
Original file line number Diff line number Diff line change
@@ -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()