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 7653191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:58:03+00:00 2026-05-31T11:58:03+00:00

def add(a, b): print ADDING %d + %d % (a, b) return a +

  • 0
def add(a, b):
    print "ADDING %d + %d" % (a, b)
    return a + b

def subtract(a, b):
    print "SUBTRACTING %d - %d" % (a, b)
    return a - b

def multiply(a, b):
    print "MULTIPLYING %d * %d" % (a, b)
    return a * b

def divide(a, b):
    print "DIVIDING %d / %d" % (a, b)
    return a / b


print "Let's do some math with just functions!"

age = add(30, 5)
height = subtract(78, 4)
weight = multiply(90, 2)
iq = divide(100, 2)

print "Age: %d, Height: %d, Weight: %d, IQ: %d" % (age, height, weight, iq)



print "Here is a puzzle."

# why does the line of code below work in this way?
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))

print "That becomes: ", what, "Can you do it by hand?"

The first thing that the line below the comment does is to call the function divide. I’m curious, why does it do that? Is it because python actually understands the order of operations or is it because of the chain structure that this line has?

  • 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-05-31T11:58:05+00:00Added an answer on May 31, 2026 at 11:58 am

    Think about it. How would you call add() when you don’t know what the result of subtract() is? How would you call subtract() if you don’t know what the result of multiply() is? Finally, how would you call multiply() if you don’t know what the result of divide() is?

    As with algebraic notation, operations inside parentheses get done first. If there are parentheses inside parentheses, the innermost operations are done first. It can’t work any other way.

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

Sidebar

Related Questions

test.py def add(a,b): print a,b,a+b return a+b c program #include <python.h> int _tmain(int argc,
class Ball: a = [] def __init__(self): pass def add(self,thing): self.a.append(thing) def size(self): print
I would like to do something like the following: def add(a, b): #some code
I'm trying to create a class that will allow me to add/multiply/divide objects of
def initialize(apps, catch=404) @apps = []; @has_app = {} apps.each { |app| add app
On 2.7.5.final, I'm attempting to add a Iterable list of Ints like so def
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
I want to automatically add some items to a model's ManyToMany field when it
I want to add the option to register with a JSON format and some
I want to have dict / list to which I can add values, just

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.