Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:54:34+00:00 2026-06-13T14:54:34+00:00

I am messing around with the lambda function and I understand what I can

  • 0

I am messing around with the lambda function and I understand what I can do with it in a simple fashion, but when I try something more advanced I am running into errors and I don’t see why.

Here is what I am trying if you can tell me where I am going wrong it would be appricated.

import math

C = lambda n,k: math.factorial(n)/(math.factorial(k))(math.factorial(n-k))

print C(10,5)

I should note that I am running into errors trying to run the code on Codepad. I do not have access to Idle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:54:36+00:00Added an answer on June 13, 2026 at 2:54 pm

    Try this:

    from math import factorial
    from __future__ import division
    
    C = lambda n, k : factorial(n) / factorial(k) * factorial(n-k)
    
    print C(10,5)
    > 3628800.0
    

    You were missing a *, and also it’s possible that the division should take in consideration decimals, so the old division operator / won’t do. That’s why I’m importing the new / operator, which performs decimal division.

    UPDATE:

    Well, after all it seems like it’s Codepad’s fault – it supports Python 2.5.1, and factorial was added in Python 2.6. Just implement your own factorial function and be done with it, or even better start using a real Python interpreter.

    def factorial(n):
        fac = 1
        for i in xrange(1, n+1):
            fac *= i
        return fac
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been messing around with something that should be simple. I've moved jobs and
When messing around with Haskell using GHC, I can use various meta-commands like :i
been messing around with JFrames a bit, and I noticed something: JFrame frame =
I been messing around with the css but i cannot get the layout I
I'm messing around with bitwise operations and wanted to implement the simple logic puzzle
I've been messing around with Android development. I made a simple form that has
I'm messing around with expression trees, but I'm little stuck. I have this expression:
While messing around with the custom formatting options in Eclipse, in one of the
I've been messing around with this for hours trying different ways of ordering by
I've been messing around with some coding and finally think I'm finally ready for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.