Home > Software design >  how can I use builtin function in my python divisor code?
how can I use builtin function in my python divisor code?

Time:12-19

I'm getting error on the line with (if counter > max_count:). It says not supported between instances of 'int' and 'builtin_function_or_method'. I can't underestand what is the problem!

def divisors(num):
    counter=1
    for i in range(1,num):
        x = num%i
        if x==0:
            counter =1
    return counter

max_count= 0
Number=0
for i in range(3):
    number = int(input('\nEnter the Number : '))
    counter=divisors(number)

    if counter > max_count:
        max_count=counter
        Number=number

    elif counter==max_count:
        max_count=max

        if number>Number:
            Number=number    
    

print('\n',Number,max_count)

CodePudding user response:

You have a typo on max function, or just missed to defines the scope.

Current: max

Expected: max([value_a, value_b]), or just nothing. This depends on your purpose.

Using only "max" will return <built-in function max> has value of max_count when both equal.

  • Related