The Joy of Computing using Python | NPTEL 2023 | Week 4 Assignment Solutions

ABOUT THE COURSE :
The Joy of Computing Using Python Week 4

A fun filled whirlwind tour of 30 hrs, covering everything you need to know to fall in love with the most sought after skill of the 21st century. The course brings programming to your desk with anecdotes, analogies and illustrious examples. Turning abstractions to insights and engineering to art, the course focuses primarily to inspire the learner's mind to think logically and arrive at a solution programmatically. As part of the course, you will be learning how to practice and culture the art of programming with Python as a language. At the end of the course, we introduce some of the current advances in computing to motivate the enthusiastic learner to pursue further directions.

Course Status     :    Upcoming
Course Type        :    Elective
Duration               :    12 weeks
Start Date            :    23 Jan 2023
End Date              :    14 Apr 2023
Exam Date           :    29 Apr 2023 IST
Enrollment Ends :    30 Jan 2023

CRITERIA TO GET A CERTIFICATE :

Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

NOTE: Please note that there will not be an unproctored programming exam for this course this term.

The Joy of Computing using Python Week 4 Assignment Solutions :-


Q1) Which of the following statements are true with regards to magic square?

a) The sum of each row should be m.
b) The sum of each column should be m.
c) The sum of each diagonal should be m.
d) None of the above

Answer :- (a), (b), (c)

Q2) Which of the following statements hold true about N in the magic square? N denotes the number of rows and columns in the square.

a) N should be even.
b) N should be odd.
c) N can be even or odd.
d) N can take any value.

Answer :- (b) N should be odd.

Q3) Which of the following statements are true regarding the Magic Squares? (N = Number of rows or columns)

a) A Magic Square is always a square matrix.
b) A Magic Square can or cannot be a square matrix.
c) The Sum of each row and each column is N(N+1)/2
d) The Sum of each row and each column is N(N2+1 )/2.

Answer :- (a), (d)

Q4) What will be the output of the following code?
week 4 que 4
a) This is a sentence.
b) Error
c) No output
d) The program will not run.

Answer :- (c) No output

Q5) Which of the following operator is used to raise the exponent to a number?

a) ^
b) *
c) **
d) ***

Answer :- (c) **

Q6) Suppose there is a movie with 3 letters, how many combinations of names are possible?

a) 26
b) 676
c) 17576
d) 456976

Answer :- (c) 17576

Q7) What should be the value of a, b, c, d respectively?
week 4 que 7
a) 1,3,9,7
b) 9,3,7,1
c) 1,7,3,9
d) 7,3,9,1

Answer :- (c) 1,7,3,9

Q8) What will be the output of the following code?
week 4 que 8
a) Print unique movies of list L1
b) Print unique movies of list L2
c) Print unique movies of list L1 and L2
d) Shows an error

Answer :- (a) Print unique movies of list L1

Q9) What will be the output of the following code?
week 4 que 9
a) Print all perfect squares with square roots between 5-20 and divisible by 5.
b) Print all perfect squares with square roots between 5-20 and not divisible by 5.
c) Print all perfect squares with square roots between 5-19 and not divisible by 5.
d) Print all perfect squares with square roots between 5-19 and divisible by 5.

Answer :- (d) Print all perfect squares with square roots between 5-19 and divisible by 5.

Q10) A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For example, 6 is a perfect number as the sum of its divisors 1,2,3 is equal to 6.
Which function will return True if the number is a perfect number?

a) week 4 que 10 a

b) week 4 que 10 b

c) week 4 que 10 c

d) week 4 que 10 d
Answer :- (a)

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)

Code :-  
Week 4 Programming Assignment 1
n=int(input())
ans=0
for i in range(1,n+1):
  ans+=i**2
print(ans,end="") 

Week 4 Programming Assignment 2 :-

Write a 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)

Code :- 
Week 4 Programming Assignment 2
n=int(input())
print(2**n,end="")

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

Code :-
Week 4 Programming Assignment 3
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

Join us :