D
danielj
There is a song that goes like this:
On the first day of Christmas, my true love sent to me a partridge
in a pear tree.
On the second day of Christmas, my true love sent to me two turtle
doves and a partridge in a pear tree.
...
If this goes on for the 12 days of Christmas. How many presents will
your true love send you over Christmas?
<strong>(Hint: You will need a loop inside another). </strong>
I don't think you need a loop inside a loop.... Here is what I did:
day = 0
gifts = 0
12.times do
day = day + 1
gifts = gifts + day
end
print gifts
Does anyone know how you would do it with a <em>loop inside a loop</
em>?
On the first day of Christmas, my true love sent to me a partridge
in a pear tree.
On the second day of Christmas, my true love sent to me two turtle
doves and a partridge in a pear tree.
...
If this goes on for the 12 days of Christmas. How many presents will
your true love send you over Christmas?
<strong>(Hint: You will need a loop inside another). </strong>
I don't think you need a loop inside a loop.... Here is what I did:
day = 0
gifts = 0
12.times do
day = day + 1
gifts = gifts + day
end
print gifts
Does anyone know how you would do it with a <em>loop inside a loop</
em>?