def add(a, B)/>: print "ADDING %d + %d" % (a, B)/> return a + b def subtract(a, B)/>: print "SUBTRCTING %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 "Lets do some maths 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) #puzzle for the extra credit, type this in anyway print "here is the puzzle." what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) print "That becomes what? Can you do it by hand?" # add(age, subtract(height, multiply(weight, 25))) # add(age, subtract(height, multiply(205, 25))) # add(age, subtract(height, 230)) # add(age, subtract(74, 230)) # add(age, 304) # add(age, 304) # add = 339

# Solving a Simple Puzzle Involving Brackets

Page 1 of 1## 2 Replies - 682 Views - Last Post: 24 August 2011 - 03:17 PM

### #1

# Solving a Simple Puzzle Involving Brackets

Posted 24 August 2011 - 12:48 PM

ok so I need someone to check my work essentially. Is the answer correct? Does it make sense to you?

##
**Replies To:** Solving a Simple Puzzle Involving Brackets

### #2

## Re: Solving a Simple Puzzle Involving Brackets

Posted 24 August 2011 - 01:09 PM

Well no it turns out I was wrong and I still cannot get to the right answer. Here is the new updated code. The answer is -4391 I need to try and get to that answer. has anyone any ideas?

def add(a, B)/>: print "ADDING %d + %d" % (a, B)/> return a + b def subtract(a, B)/>: print "SUBTRCTING %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 "Lets do some maths 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) #puzzle for the extra credit, type this in anyway print "here is the puzzle." what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) print "That becomes", what , "Can you do it by hand?" # add(age, subtract(height, multiply(weight, 25))) # add(age, subtract(height, multiply(205, 25))) # add(age, subtract(height, 230)) # add(age, subtract(74, 230)) # add(age, 304) # add(age, 304) # add = 339

### #3

## Re: Solving a Simple Puzzle Involving Brackets

Posted 24 August 2011 - 03:17 PM

monster92, on 24 August 2011 - 04:09 PM, said:

Well no it turns out I was wrong and I still cannot get to the right answer. Here is the new updated code. The answer is -4391 I need to try and get to that answer.

??? got that:

[email protected]:~$ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def add(a, B)/>: ... print "ADDING %d + %d" % (a, B)/> ... return a + b ... >>> >>> def subtract(a, B)/>: ... print "SUBTRCTING %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 "Lets do some maths with just functions!" Lets do some maths with just functions! >>> >>> age = add(30, 5) ADDING 30 + 5 >>> height = subtract(78, 4) SUBTRCTING 78 - 4 >>> weight = multiply(90, 2) MULTIPLYING 90 * 2 >>> iq = divide(100, 2) DIVIDING 100 / 2 >>> >>> print "age: %d, height: %d, weight %d, IQ %d" % (age, height, weight, iq) age: 35, height: 74, weight 180, IQ 50 >>> >>> #puzzle for the extra credit, type this in anyway ... >>> print "here is the puzzle." here is the puzzle. >>> >>> what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) DIVIDING 50 / 2 MULTIPLYING 180 * 25 SUBTRCTING 74 - 4500 ADDING 35 + -4426 >>> >>> print "That becomes", what , "Can you do it by hand?" That becomes -4391 Can you do it by hand? >>>

Your code looks fine. Can't imagine what the issue is.

Page 1 of 1