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

  • Home
  • SEARCH
  • 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 9241861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:27:23+00:00 2026-06-18T08:27:23+00:00

I come to this point when I was making a simple calculator. I did

  • 0

I come to this point when I was making a simple calculator. I did a simple program to sum the list of numbers as follows, But the program for multiplication is a little bit long.

So can anybody have any idea how to make short program to multiple list of numbers in python. Here is my code what looks like.

def calculate(oper,*nm):
    return oper(nm)

add=lambda x:sum(x)

def mult(lst):
    tmp=1
    for i in lst:
        tmp*=i
    return tmp

calculate(add,2,34,2)

calculate(mult,8,5,7)

  • 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-18T08:27:24+00:00Added an answer on June 18, 2026 at 8:27 am

    Really, you do not need to define calculate because Python already has a name for it: reduce.

    def calculate(oper, *nm):
        return reduce(oper, nm)
    
    In [6]: import operator
    
    In [7]: calculate(operator.add, 2, 34, 2)
    Out[7]: 38
    
    In [8]: calculate(operator.mul, 8, 5, 7)
    Out[9]: 280
    

    Note: In Python3, reduce has been moved to the functools module. (Thanks to @ErikRoper for pointing this out.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going through this tutorial about PDO and have come to the point
I've been trying to come up with an interest point detection algorithm and this
I come across this code in my web.xml but I don't understand what it
Making the usual blob tracker with OpenCV and cvBlobsLib, I've come across this problem
I've been searching far and long, and to this moment, I did not come
all. This question probably has a devilishly simple answer but it has kept me
I'm making a pretty simple game just for fun/practice but I still want to
I'm making a little web application using PHP and JavaScript and I've come to
I have come to a point in my program where my polymorphism is broken.
How come this works: import datetime now = datetime.datetime.now() month = '%d' % now.month

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.