My backwards logic

Juan Christian juan0christian at gmail.com
Fri Sep 5 21:34:21 CEST 2014


What's [snip] ??


On Fri, Sep 5, 2014 at 3:48 PM, MRAB <python at mrabarnett.plus.com> wrote:

> On 2014-09-05 18:35, Juan Christian wrote:
>
>> I made this code just for fun and learning, it's working, but would this
>> be a good approach? Thanks.
>>
>> import sys
>>
>>
>> def prime_checker(start = 1, stop = 1):
>>
>
> In Python, the standard is to use a half-open range.
>
>      for number in range(start, stop + 1):
>>         divisors = [(number % x) for x in range(1, number + 1)]
>>             print("{n} prime? {r}".format(n = number, r =
>> (divisors.count(0) == 2)))
>>
>>  You want to know only whether it's prime, so why continue looking after
> finding a factor?
>
>>
>> if __name__ == '__main__':
>>     prime_checker(int(sys.argv[1]), int(sys.argv[2]))
>>
>>  [snip]
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140905/5c1b5bea/attachment.html>


More information about the Python-list mailing list