# The Joy Of Computing Using Python Week 4 Programming Assignments | NPTEL | Answers Jan 2023

## Write a program that takes a number `n` as input and prints the sum of the squares of the first `n` positive integers. Example: If n = 4, the program should output 30 (1^2 + 2^2 + 3^2 + 4^2 = 30)

```n = int(input())
sum_of_squares = 0

for i in range(1, n+1):
sum_of_squares += i**2

print(sum_of_squares)
```

## Write a Python program that takes a number `n` as input and prints the nth power of 2. Example: If n = 4, the program should output 16 (2^4 = 16)

```n = int(input())
result = 2 ** n
print(result)
```

## Write a program that takes a number `n` as input and prints a pyramid of numbers with `n` rows. Example: If n = 5, the program should output the following

```    1
232
34543
4567654
567898765
```
```n=int(input())
max_row=1
max_row1=1

for row in range(1,n+1):
b=0
for space in range(1,n-row+1):
print(" ",end="")

a=row
Left=list()
while(a!=max_row1):

if a>9:
Left.append(str(b))
b=b+1
else:
Left.append(str(a))
a=a+1
if row==n:
print(("".join(Left)+str(max_row)+"".join(Left[::-1])),end="")
else:
print(("".join(Left)+str(max_row)+"".join(Left[::-1])))
if (max_row+2>9):
max_row=-1
max_row+=2
max_row1+=2
```

Disclaimer:
" This page contains Programming Assignment related to The Joy of Computing using Python . The answers to these questions are provided for educational and informational purposes only.These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself."