简体   繁体   中英

how can I use builtin function in my python divisor code?

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM