[Tutor] To find the least number divisible by all numbers from 1-20
Alan Gauld
alan.gauld at btinternet.com
Tue Aug 13 20:10:28 CEST 2013
On 13/08/13 18:19, Alan Gauld wrote:
> On 13/08/13 17:45, #PATHANGI JANARDHANAN JATINSHRAVAN# wrote:
>
>> def check(num):
>> lis=[20,19,18,17,16,14,13,11] #because a no. divisible by 20 is
>> for i in lis:
>> if num%i==0:
>> continue
>> else:
>> return False
>> break
>>
>> return True
>
> This is a bit convoluted. All you need is
>
> for i in lis:
> if num%i != 0:
> return False
> return True
Oops, that last return should be outside the loop, sorry...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list