# NPTEL The Joy Of Computing Using Python Assignment 3 Answers

NPTEL The Joy of Computing using Python Assignment 3 Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge.

## NPTEL The Joy of Computing using Python Assignment 3 Answers [July 2022]

1. Which of the following statements describes the challenge ‘Fizz Buzz’?

a. Multiples of 3 should print buzz, multiples of 5 should print fizz, and multiples of 3 and 5 should print fizz buzz.
b. Multiples of 3 should print fizz, multiples of 5 should print buzz, and multiples of 3 or 5 should print fizz buzz.
c. Multiples of 3 should print fizz, multiples of 5 should print buzz, and multiples of 3 and 5 should print fizz buzz.
d. Multiples of 3 should print buzz, multiples of 5 should print fizz, and multiples of 3 and 5 should print fizz buzz.

`Answer:- c`

2. random.randint(1,100) will generate a number _________.(assume random is imported)

a. Between 1,100 both inclusive.
b. Between 1,100 both exclusive.
c. Between 1,100 only 100 inclusive.
d. Between 1,100 only 1 inclusive.

`Answer:- a`

3. Consider a string of 20 digits initialized with all zeros as a DNA sequence, in the context of lectures, updating a random ‘zero’ as ‘one’ implies ___.

a. Updating a random number
b. Evolution
d. Increase

`Answer:- b`

4. Which of the following method is correct to add an element at a specific position?

a. insert()
c. append()
d. index()

`Answer:- a`

5. What will be the output of the following program?

a. Python, C++, Java, Kotlin
b. 0, 1, 2, 3
c. 0, 1, 2, 3, 4
d. Python, C++, Java

`Answer:- b`

6. Which of the following methods is correct to count the number of instances on an element in a list?

a. total()
b. sum()
c. count()
d. numberof()

`Answer:- c`

7. In the Fizz Buzz game, What will be the output if the number is 285?

a. Fizz
b. Buzz
c. Fizz Buzz
d. No output

`Answer:- c`

8. Which of the following keywords is used to define a function in python?

a. func
b. function
c. define function
d. def

`Answer:- d`

9. Which of the following statements are true about crowd-sourcing?

`Answer:- For Answers Click Here`

10. Which of the following commands is not correct in order to generate a graph?

`Answer:- d`

## NPTEL The Joy Of Computing Using Python Assignment 3 Programming Solutions

Q1. There is list L containing some numbers. Write a program to create a new list which contains the numbers which are either divisible by 5 or 7 or both. Print that new list in ascending order.

Code:-

``````ans=[z for z in L if z%5==0 or z%7==0]
print(sorted(ans),end="")``````

Q2. Write a function rev which takes a list L and integer n and print the first n largest numbers of the list.

Code:-

``````def rev(L,n):
print(sorted(L)[::-1][:n],end="")
``````

Q3. Write a program to count and print the number of odd numbers in a list L.

Code:-

``````odd=[a for a in L if a%2!=0]
print(len(odd),end="")``````

## What is The Joy Of Computing Using Python?

The Joy Of Computing Using Python is 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. This course includes examples of analytics in a wide variety of industries, and we hope that students will learn how you can use analytics in their careers and life. One of the most important aspects of this course is that you, the student, are getting hands-on experience creating analytics models; we, the course team, urge you to participate in the discussion forums and to use all the tools available to you while you are in the course!

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the 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 THE 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.

## NPTEL The Joy Of Computing Using Python Assignment 3 Answers Jan 2022

Q1. What will be the output of the following code?

(A) Practice,Practice,Practice,Practice,Practice
(B) Practice makes the man perfect.
(C) Practice makes man perfect. the
(D) Makes man perfect. Practice the

Answer:- (C) Practice makes man perfect. the

Q2. What should be the code to print all Even numbers between 1-10 (both inclusive)?

Q3. What will be the output of the following code?

(A) Sorted List(L) containing random elements between 0-10 in descending order.
(B) Sorted List containing random elements between 0-10 in ascending order.
(C) Sorted List containing elements between 0-10.
(D) Sorted List containing elements between 0-9 in ascending order.

Answer:- (A) Sorted List(L) containing random elements between 0-10 in descending order.

Q4. What will be the output of the following code?

(A) we were here together
(B) we were here
(C) we were
(D) we

Q5. What will be the value of list L?

(A) [‘Even’, ‘Odd’, ‘Even’, ‘Odd’]
(B) [‘Even’, ‘Odd’, ‘Even’, ‘Odd’, ‘Even’, ‘Odd’]
(C) [‘Even’, ‘Odd’, ‘Even’, ‘Even’, ‘Even’]
(D) [‘Even’, ‘Odd’, ‘Even’, ‘Odd’, ‘Even’]

Q6. What is the correct code for a function to return the sum of elements of list L?

Q7. What does the following code represent?

(A) Checks if a is divisible by b.
(B) Checks if b is divisible by a.
(C) Checks if a and b are multiples of 5.
(D) None of the above.

Answer:- (A) Checks if a is divisible by b.

Q8. Suppose there exists a file named file.txt. What the following code will do?

(A) Print whatever is there in the file and add hey there.
(B) Throws an error in the end as the file is not opened in writable mode.
(C) Throws an error in the end as the file is not opened in readable mode.
(D) No error will be thrown and the code will work fine.

Answer:- (B) Throws an error in the end as the file is not opened in writable mode.

Q9. Suppose there is an empty file named file.txt. What will be the output of the following code?

(A) writing this file again
(B) hey there!!
(C) hey there!!writing this file again
(D) Throws an error

Answer:- (C) hey there!!writing this file again

Q10. What will be the output of the following code?

(A) Alternative 1’s and 0’s respectively
(B) Alternative 0’s and 1’s respectively.
(C) All Zeroes towards left and ones towards the right.
(D) All ones towards the left and zeroes towards the right.

Answer:- (A) Alternative 1’s and 0’s respectively

The Joy Of Computing Using Python Programming Assignment week 3

Q1. You are given a list named L. Print all the elements at odd position of list L.(We will take care of the input, you just have to print elements present at odd position)

Code:-

``````for a in range(len(L)):
if a%2!=0:
if len(L)-a<=2:
print(L[a],end="")
else:
print(L[a])``````

Q2. You are given a list L. Print the list of first 3 smallest elements in ascending order and last 2 greatest elements in descending order of the list L respectively.(We will take care of the input)

Code:-

``````print(sorted(L)[:3])
print(sorted(L)[::-1][:2],end="")``````

Q3. You are given a list L. Write a function all_even that accepts the list Land print all the even numbers is the list L.(Order of the numbers should be same as the order present in the list)

Code:-

``````def all_even(L):
ans=[]
for i in L:
if i%2==0:
ans.append(i)
for a in range(len(ans)):
if a==len(ans)-1:
print(ans[a],end="")
else:
print(ans[a])``````