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

The Joy of Computing using Python Week 4 - Programming Assignments | NPTEL | Answer with Explanation

The Joy Of Computing Using Python Week 4 Programming Assignments | NPTEL | Answers Jan 2023
"Discover the Excitement of Computing with Python | Week 4 Programming Assignment - Get ready to enhance your programming skills and deepen your understanding of the Python language with this week 4 Programming Assignments on 'The Joy of Computing using Python'. Test your knowledge and boost your confidence as a Python programmer today!"

The Joy Of Computing Using Python Week 4: Programming Assignment 1

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)

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

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

print(sum_of_squares)

The Joy Of Computing Using Python Week 4: Programming Assignment 2

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)

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

The Joy Of Computing Using Python Week 4: Programming Assignment 3

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
Answer
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."

The Joy of Computing using Python Week 4,NPTEL, Week 4: Programming Assignment 1,2 and 3 [Jan 2023],noc23_cs20

Post a Comment

0 Comments