-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
39 lines (31 loc) · 986 Bytes
/
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
def multiply_numbers(a, b):
return a * b
def reverse_list(input_list):
return input_list[::-1]
def calculate_discount(price, discount_percentage):
if not (0 <= discount_percentage <= 100):
raise ValueError("Discount percentage must be between 0 and 100")
return price * (1 - discount_percentage / 100)
class MathOperations:
def is_prime(self, n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def factorial(self, n):
if n < 0:
raise ValueError("Factorial not defined for negative numbers")
if n == 0:
return 1
result = 1
for i in range(1, n + 1):
result *= i
return result