-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice_functions.py
53 lines (39 loc) · 975 Bytes
/
practice_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def find_square_root(x):
i = 0
while i <= (x // 2) + 1:
if i * i == x:
return i
i += 1
return -1
def is_prime(x):
if 2 >= x > 0:
return True
i = 2
while i < x:
if x % i == 0:
return False
i += 1
return True
def product_by_addition(a, b):
if a == 0:
return 0
return b + product_by_addition(a - 1, b)
def rev_bubble_sort(A):
for i in range(len(A)):
for j in range(len(A) - i-1):
if A[j] > A[j + 1]:
temp = A[j]
A[j] = A[j + 1]
A[j + 1] = temp
return A
print(find_square_root(10))
print(find_square_root(9))
print(find_square_root(1))
print(is_prime(1))
print(is_prime(2))
print(is_prime(7))
print(is_prime(12))
print(is_prime(15))
print(product_by_addition(0, 20))
print(product_by_addition(10, 20))
print(rev_bubble_sort([9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]))