curriculum/challenges/english/blocks/daily-coding-challenges-python/69b1028d6e265413d0198a29.md
Given an integer n, return the nth row of Pascal's triangle as an array.
In Pascal's Triangle, each row begins and ends with 1, and each interior value is the sum of the two values directly above it.
Here's the first 5 rows of the triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
pascal_row(5) should return [1, 4, 6, 4, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(5), [1, 4, 6, 4, 1])`)
}})
pascal_row(3) should return [1, 2, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(3), [1, 2, 1])`)
}})
pascal_row(1) should return [1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(1), [1])`)
}})
pascal_row(10) should return [1, 9, 36, 84, 126, 126, 84, 36, 9, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(10), [1, 9, 36, 84, 126, 126, 84, 36, 9, 1])`)
}})
pascal_row(15) should return [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(15), [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1])`)
}})
def pascal_row(n):
return n
def pascal_row(n):
if n == 1:
return [1]
row = [1]
for _ in range(2, n + 1):
next_row = [1]
for i in range(1, len(row)):
next_row.append(row[i - 1] + row[i])
next_row.append(1)
row = next_row
return row