Solving a Simple Puzzle Involving Brackets

Page 1 of 1

2 Replies - 518 Views - Last Post: 24 August 2011 - 03:17 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=244668&amp;s=11ea69cfdd5ed732006081d94d288e61&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 monster92

• New D.I.C Head

Reputation: 1
• Posts: 30
• Joined: 10-May 11

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?

```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 = 339
```

Is This A Good Question/Topic? 0

Replies To: Solving a Simple Puzzle Involving Brackets

#2 monster92

• New D.I.C Head

Reputation: 1
• Posts: 30
• Joined: 10-May 11

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 = 339
```

#3 baavgai

• Dreaming Coder

Reputation: 6340
• Posts: 13,547
• Joined: 16-October 07

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:
```baavgai@DIC:~\$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
>>> 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.