Last active
April 27, 2020 18:47
-
-
Save saipraveenkondapalli/55bfd5cb899ba3506af41738c5ab7e17 to your computer and use it in GitHub Desktop.
prime factors of a number,using definatons,ehile loop and for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prime_number(n): | |
for n in range(2, n + 1): | |
if n > 1: | |
for y in range(2, n): | |
if n % y == 0: | |
break | |
else: | |
prime.append(n) | |
ans = list() | |
final = list() | |
prime = list() | |
def process(y): | |
while y > 1: | |
for i in range(len(prime)): | |
if y % prime[i] == 0: | |
y = y / prime[i] | |
ans.append(prime[i]) | |
break | |
def factor_form(): | |
for p in range(len(ans)): | |
while ans[p] not in final: | |
final.append(ans[p]) | |
for x in range(len(final)): | |
print(f"{final[x]}^{ans.count(final[x])}", end="* ") | |
print("1") | |
num = int(input("enter a number: ")) | |
prime_number(num) | |
process(num) | |
print(f"the prime factors of {int(num)} is {ans}") | |
factor_form() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment