### The Joy of Computing using Python Week 4 Assignment

**Course name: The Joy of Computing Using Python**

Link to Enroll: Click here

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

**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(N^{2} +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**

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

**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**

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

**Q7. What is the command to print the last result of the ipython console?**

a. ‘’

b. –

c. _

d. \\

**Answer: c**

**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**

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

**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**

**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**

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

## Python Assignment 4 Programming Solutions

**Question 1Take 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:NKOutput:A list LExample-Input:52Output:[1, 0, 1, 0, 1]**

**Solution:**

```
N=int(input())
K=int(input())
L= []
if K%2!=0:
for i in range(N):
if i%2==0:
L.append(0)
else:
L.append(1)
else:
for i in range(N):
if i%2!=0:
L.append(0)
else:
L.append(1)
print(L, end="")
```

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

**Question 2Write a program to take string S as an input and replace all vowels by *. Also print the modified string.InputA string SOutputModified string**

**Solution:**

```
S=input()
v=list('aeiou')
a=""
for i in S:
if i.lower() in v:
a=a+'*'
else:
a=a+i
print(a,end="")
```

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

**Question 3Write a program to take an integer N as an input and display the pattern**

**Solution:**

```
N=int(input())
for i in range(N):
for j in range(i+1):
print('* ',end="")
print()
for i in range(N-1,0,-1):
for j in range(i):
print("* ",end="")
if j!=0:
print()
```

**This is an assignment for The Joy of Computing using Python Week 4 Assignment**

More Weeks solutions of this course: https://progies.in/answers/nptel/the-joy-of-computing-using-python

More NPTEL Solution: https://progies.in/answers/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.