---
# System prepended metadata

title: 'level 5: Perimeter of squares in a rectangle (2019-11-22)'
tags: [python, Codewars]

---

###### tags: `Codewars` `python`

# level 5: Perimeter of squares in a rectangle (2019-11-22)

The drawing shows 6 squares the sides of which have a length of 1, 1, 2, 3, 5, 8. It's easy to see that the sum of the perimeters of these squares is : 4 * (1 + 1 + 2 + 3 + 5 + 8) = 4 * 20 = 80

Could you give the sum of the perimeters of all the squares in a rectangle when there are n + 1 squares disposed in the same manner as in the drawing:
![](https://i.imgur.com/A32YrxP.png)
The function perimeter has for parameter n where n + 1 is the number of squares (they are numbered from 0 to n) and returns the total perimeter of all the squares.

perimeter(5)  should return 80
perimeter(7)  should return 216

my code:
<pre>
def perimeter(n):
    number=[0,1]
    for i in range(2,n+2):
        number.append( number[i-1] + number[i-2] )        
    num = sum(number)*4
    return num
</pre>
