Loving Python - Chapter 4 just uploaded!

3 views
Skip to first unread message

MM.Brian

unread,
Jan 1, 2010, 3:11:12 AM1/1/10
to sharifpython88
Salam :)
darin chapter az teknikha va tavabeiy ke pish az in moarrefi shodan
estefade shode. tamame mataleb ghabele estefade dar halle soalaye
projecteuler hastan.
Movaffagh Bashid :)

Content: all and any functions, reduce function, the global statement,
introducing lambda functions and the most efficient way to calculate
factorial of a number.
Writer: Mohsen Mansouryar
Advisor: Milad Heydariaan
Link: http://sharifpython88.googlegroups.com/web/Loving%20Python%20-%20Chapter%204.pdf?gsc=bQ1PgQsAAAC8TLdNF_fYKYZyvOaebgjV

azin azadi

unread,
Jan 1, 2010, 1:51:30 PM1/1/10
to sharifp...@googlegroups.com
ki mitune bege ke daghighan be che ellati raveshi ke dar akhar avorde shode sari'tar az digar ravesh-ha kar mikone?
--
  ****************************************
 *                    Azin Aazadi                  *
*      Student of Computer Science        *
*  Department of Mathematical science    *      
*     Sharif University of Technology       *
 *                                                    *
  ****************************************

MM.Brian

unread,
Jan 4, 2010, 12:43:14 PM1/4/10
to sharifpython88
khob, mese inke kasi alaghemand nist javab bede :D

inke chera az digar raveshaiy ke khodemun factorial ro tarif mikonim
saritare ke taghriban vazehe. albate age bedune estefade az reduce ba
raveshe gheyre recursive (hamun fore sade) age bejaye range, xrange
bekar bebarim taghriban ba hamin sorat mohasebe mikone (yekam
kondtar). amma chera az math.factorial saritare!!?, khob yekam
bedalile error checking haiy hast ke math.factorial anjam mide
(masalan adad nabayad manfi ya float bashe), hamchenin 0! bayad joda
tarif beshe darsoorati ke ba estefade az reduce, 0! tarif nemishe.

module mathe python darune interpretere python tarif shode.
baghiashunam intory mishe fahmid:
>>> import sys
>>> sys.builtin_module_names
in yani tamamie tavabeesh ba C neveshte shodan.
age ye negahi be code factorial tu mathmodule.c (linke zir) bendazin,
goftehaye balaro taid mikone :)
http://svn.python.org/view/python/trunk/Modules/mathmodule.c?view=markup&pathrev=64050

linke zir etelaate arzeshmanD darbaraye chegunegie test kardane sorate
in function tu python dar ekhtiar mizare.
http://stackoverflow.com/questions/1041348/unable-to-make-a-factorial-function-in-python


On Jan 1, 9:51 pm, azin azadi <aaz...@gmail.com> wrote:
> ki mitune bege ke daghighan be che ellati raveshi ke dar akhar avorde shode
> sari'tar az digar ravesh-ha kar mikone?
>

> On Fri, Jan 1, 2010 at 3:11 AM, MM.Brian <mohsen.br...@gmail.com> wrote:
> > Salam :)
> > darin chapter az teknikha va tavabeiy ke pish az in moarrefi shodan
> > estefade shode. tamame mataleb ghabele estefade dar halle soalaye
> > projecteuler hastan.
> > Movaffagh Bashid :)
>
> > Content: all and any functions, reduce function, the global statement,
> > introducing lambda functions and the most efficient way to calculate
> > factorial of a number.
> > Writer: Mohsen Mansouryar
> > Advisor:  Milad Heydariaan
> > Link:

> >http://sharifpython88.googlegroups.com/web/Loving%20Python%20-%20Chap...

azin azadi

unread,
Jan 4, 2010, 1:25:18 PM1/4/10
to sharifp...@googlegroups.com
خیلی عجیبه. به نظرم دلیل پایه ای تری باید داشته باشه. این چک ها اونقدری زمان مصرف نمیکنند.

MM.Brian

unread,
Jan 4, 2010, 5:50:28 PM1/4/10
to sharifpython88
movafegham :D 2 3 ta if zamani nemigiran.
man inja harfe ghablimo ke goftam ba reduce 0! tarif nemishe pas
migiram. intory mishe:
>>> #behtare bejaye tarife zarb az mul estefade konim
>>> from operator import mul
>>> def Factorial(n): return reduce(mul,xrange(1,n+1),1) #1 is the initial value

>>> Factorial(0)
1
>>> Factorial(5)
120
>>>

edeaye ghablimam mabni bar inke raveshe fogh saritarine pas migiram
chon rahe saritari ham hast!:
>>> from gmpy import fac #http://code.google.com/p/gmpy/
>>> fac(0)
mpz(1)
>>> fac(5)
mpz(120)
>>> #in function kheyli saritar az raveshe ghablie! :D

source: http://adammonsen.com/post/173/comment-page-1
http://python.genedrift.org/2008/06/06/a-quick-assessment-of-factorial-functions-in-python/

linkaye bala mitunan dar javab be soale ostad mofid bashan vali hanuz
ham javabi ke khodamam ghane kone peyda nakardam :(

Best :)

On Jan 4, 9:25 pm, azin azadi <aaz...@gmail.com> wrote:
> خیلی عجیبه. به نظرم دلیل پایه ای تری باید داشته باشه. این چک ها اونقدری زمان
> مصرف نمیکنند.
>
>
>
> On Mon, Jan 4, 2010 at 12:43 PM, MM.Brian <mohsen.br...@gmail.com> wrote:
> > khob, mese inke kasi alaghemand nist javab bede :D
>
> > inke chera az digar raveshaiy ke khodemun factorial ro tarif mikonim
> > saritare ke taghriban vazehe. albate age bedune estefade az reduce ba
> > raveshe gheyre recursive (hamun fore sade) age bejaye range, xrange
> > bekar bebarim taghriban ba hamin sorat mohasebe mikone (yekam
> > kondtar). amma chera az math.factorial saritare!!?, khob yekam
> > bedalile error checking haiy hast ke math.factorial anjam mide
> > (masalan adad nabayad manfi ya float bashe), hamchenin 0! bayad joda
> > tarif beshe darsoorati ke ba estefade az reduce, 0! tarif nemishe.
>
> > module mathe python darune interpretere python tarif shode.
> > baghiashunam intory mishe fahmid:
> > >>> import sys
> > >>> sys.builtin_module_names
> > in yani tamamie tavabeesh ba C neveshte shodan.
> > age ye negahi be code factorial tu mathmodule.c (linke zir) bendazin,
> > goftehaye balaro taid mikone :)
>

> >http://svn.python.org/view/python/trunk/Modules/mathmodule.c?view=mar...


>
> > linke zir etelaate arzeshmanD darbaraye chegunegie test kardane sorate
> > in function tu python dar ekhtiar mizare.
>

> >http://stackoverflow.com/questions/1041348/unable-to-make-a-factorial...

Reply all
Reply to author
Forward
0 new messages