บรรทัดเดียวก็พอ #1 factorial

def fact(x): return (1 if x<1 else x * fact(x-1))

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Comments »

 
  • bact' พูดว่า:

    แหงะ บรรทัดเดียวจริง ๆ แต่หลาย statement นะ :p

  • nuboat พูดว่า:

    def q220ss(n):
    return ‘\n’.join(['-'*((n+1)/2 - (i <= (n+1)/2 and i or 1 + n - i)) + '*'*((i 1) + '-'*((i 2 and (i <= (n+1)/2 and i or 1 + n - i) - 2 or 0) + '*'*((i <= (n+1)/2 and i or 1 + n - i) == 1) + '-'*((i 1) + '-'*((i 2 and (i <= (n+1)/2 and i or 1 + n - i) - 2 or 0) + '*'*((i 1) + '-'*((n+1)/2 - (i <= (n+1)/2 and i or 1 + n - i)) for i in range(1, n+1) ])

    เล่นบ้างบรรทัดเดียวก็เกินพอ อยากรู้ว่าทำอะไรเอาไปรันเองนะครับ ^ ^

 

ใส่ความเห็น

XHTML: คุณสามารถใช้ป้ายกำกับเหล่านี้: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>