-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_generated_code.py
More file actions
37 lines (32 loc) · 842 Bytes
/
ai_generated_code.py
File metadata and controls
37 lines (32 loc) · 842 Bytes
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
# AI Generated Python functions for Factors, Prime Check, and HCF
# Author: Surya
def factors(n):
"""Returns the factors of a number."""
result = []
for i in range(1, n+1):
if n % i == 0:
result.append(i)
return result
def is_prime(n):
"""Checks if a number is prime."""
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
def hcf(x, y):
"""Finds the HCF of two numbers."""
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller + 1):
if (x % i == 0) and (y % i == 0):
hcf = i
return hcf
# Example usage:
if __name__ == "__main__":
print("Factors of 10:", factors(10))
print("Is 7 prime?:", is_prime(7))
print("HCF of 12 and 18:", hcf(12, 18))