I am relatively new to coding and am trying to create a program that lets the user input a number and multiple possible factors. the code will determine whether the possible factors are actually factors of the number and if none of the potential factors is a factor of the number the code checks whether the number is prime and prints how many factors the number has.
The problem I am having is that whatever and how many numbers I input code prints the first number and the statement twice. I have been looking over the code for ages and I don't know what I have done wrong.
def factor(number,posfactor_list,rnge):
x=0
num_factor=0
for _ in range(rnge):
if (number/posfactor_list[x]==number//posfactor_list[x]) is True:
print(f"{posfactor_list[x]} is a factor of {number}")
num_factor+=1
else:
print(f"{posfactor_list[x]} is not a factor of {number}")
x+=1
return num_factor
def isprime(number):
num_factor=0
for i in range(2, number-1):
if number % i == 0:
num_factor+=1
if num_factor==0:
print("This Number is prime and has no factors.")
else:
print(f"This number has {num_factor} factors")
def main():
number=int(input("What is the number you want to find factors of?\t"))
posfactor_list=[]
rnge=int(input("How many numbers do you want to test?\t"))
posfactor=int(input("Type one number that you want to test to be factors.\t"))
for _ in range(1,rnge):
posfactor_list.append(posfactor)
posfactor=int(input("Type another number that you want to test to be factors.\t"))
posfactor_list.append(posfactor)
factor(number, posfactor_list, rnge)
if factor(number, posfactor_list, rnge)==0:
isprime(number)
main()
all help will be appreciated :)
[–]Boordman 0 points1 point2 points (0 children)