+ 1
can't round number
I am trying to create a prime factor searcher. However when I try to round a number in line 3 it keeps telling me that it can not round a str. And when I replace a by float(a) or int(a) it will both of the times say float object cannot be interpreted as integer. Does anyone know how this comes and how I can solve this? import math a=input() b=round(math.sqrt(float(a)),0) primes=[] for num in range(2,b): prime = True for i in range(2,num): if (num%i==0): prime = False if prime: primes.append(num) for i in primes: if int(a)%int(i)==0: print(i) print(int(int(a)/int(i))) break
2 Antworten
+ 4
Your error is to get a 'b' variable of type float, even you round it to an integer... You must change the type of var 'b' to be integer type ( not just mathematically ) to be compatible with the range() function ^^
b=int(math.sqrt(float(a)),0)