The Joy of Computing using Python | Week 4
Session Jan-Apr 2023
Course Name: The Joy of Computing using Python
Course Link: Click Here
These are answers of The Joy of Computing using Python Assignment 4 Answers
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: c. N can be even or 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, b
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q4. What will be the output of the following code?

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: a. ^
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
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q7. What should be the value of a, b, c, d respectively?

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?

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?
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.
These are answers of The Joy of Computing using Python Assignment 4 Answers
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.

b.

c.

d.

Answer: a
The Joy of Computing using Python Programming Assignmnet
Question 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)
Solution:
def sum_of_squares(n):
sum = 0
for i in range(1, n+1):
sum += i**2
return sum
n = int(input())
print(sum_of_squares(n))
These are answers of The Joy of Computing using Python Assignment 4 Answers
Question 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)
Solution:
def power_of_two(n):
return 2**n
n = int(input())
print(power_of_two(n))
These are answers of The Joy of Computing using Python Assignment 4 Answers
Question 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
Solution:
def pyramid(n):
for i in range(1, n+1):
spaces = " " * (n - i)
numbers = ""
for j in range(i, 2 * i):
numbers += str(j % 10)
for k in range(2 * i - 2, i - 1, -1):
numbers += str(k % 10)
print(spaces + numbers)
n = int(input())
pyramid(n)
These are answers of The Joy of Computing using Python Assignment 4 Answers
More Weeks of The Joy of Computing using Python: Click Here
More Nptel courses: https://progiez.com/nptel/
Session JUL-DEC 2022
Course name: The Joy of Computing Using Python
Link to Enroll: Click here
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q1. 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
Q2. What will be the output of the following code?
a. This is a sentence.
b. Error
c. No output
d. The program will not run
Answer: c
Q3. A perfect number is a number in which the sum of its proper divisors is equal to that number. For example, 6 is a perfect number as the sum of its divisors 1,2,3 is equal to 6. Which function returns True if the number is perfect?
Answer: a
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q4. 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
Q5. What are the possible outputs of the following program?
a. Any number in the range between 0,4 (Both inclusive).
b. Any number in the range between 1,4 (Both inclusive).
c. Any number in the range between 0,5 (Both inclusive).
d. Any number in the range between 1,5 (Both inclusive).
Answer: a
Q6. Birthday Paradox can be simulated with approximately _______ people.
a. 365
b. 100
c. 40
d. 20
Answer: d
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q7. What is the command to print the last result of the ipython console?
a. ‘’
b. –
c. _
d. \\
Answer: c
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q8. What will be the output of the following program?
a. Passenger, Starwars
b. spiderman, jumanji
c. spiderman, jumanji, Passenger, Starwars?
d. spiderman, Starwars
Answer: b
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q9. In the ‘Dobble Game’, if there are 8 objects on 1 card and 10 objects on another, how many comparisons are possible?
a. 8
b. 10
c. 18
d. 80
Answer: d
These are answers of The Joy of Computing using Python Assignment 4 Answers
Q10. What will be the output of the following code?
a. Display the number of consonants and name of the movie.
b. Display the number of letters and name of the movie.
c. Display the number of vowels and name of the movie.
d. Display the number of special characters and name of the movie.
Answer: c
These are answers of The Joy of Computing using Python Assignment 4 Answers
Python Assignment 4 Programming Solutions
Question 1
Take two numbers N and K as an input. Create a list L of length N and initialize it with zeros. Change the value to 1 of even indexes if k is even, otherwise change the value of odd indexes. Print list L in the end.(Consider 0 as even)
Input:
N
K
Output:
A list L
Example-
Input:
5
2
Output:
[1, 0, 1, 0, 1]
Solution:
//Code
This is an assignment for The Joy of Computing using Python Week 4 Assignment
Question 2
Write a program to take string S as an input and replace all vowels by *. Also print the modified string.
Input
A string S
Output
Modified string
Solution:
//Code
This is an assignment for The Joy of Computing using Python Week 4 Assignment
Question 3
Write a program to take an integer N as an input and display the pattern
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 4 Answers
More NPTEL Solution: https://progiez.com/nptel
* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.
More from PROGIEZ
