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

#### This is an assignment for The Joy of Computing using Python Week 3 Assignment

Q1. 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. Multiples of 3 should print fizz, multiples of 5 should print buzz, and multiples of 3 and 5 should print fizz buzz.

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

Q2. 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. Between 1,100 both inclusive.

Q3. 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

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

Q4. Which of the following method is correct to add an element at a specific position?
a. insert()
c. append()
d. index()

Q5. 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. 0, 1, 2, 3

Q6. 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()

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

Q7. 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. Fizz Buzz

Q8. Which of the following keywords is used to define a function in python?
a. func
b. function
c. define function
d. def

Q9. Which of the following statements are true about crowd-sourcing?
a. Answers received via crowdsourcing are never correct.
b, Answers received via crowdsourcing can be as good as the answer by an expert.
c. Answers received via crowdsourcing can be better than the answer by an expert.
d. Answers received via crowdsourcing are always correct.

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

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

a. import matplotlib.pyplot as plt plt.plot([1,2,3,4],[5,6,7,8],to)

b. import matplotlib.pyplot as plt plt.plot([1,2,3,4],[5,6,7,8],r–)

c. import matplotlib.pyplot as plt plt.plot([1,2,3,4],[5,6,7,8],bs)

d. import matplotlib.pyplot as plt plt.plot([1,2,3,4],[5,6,7,8],r—)

## Python Assignment 3 Programming Solutions

Question 1

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.

Input is already managed for you.

Input : A list L

Output : A new list P

Example Input : I [7, 8, 9, 10, 11]

Output : [7, 10]

Solution:

``````L = [int(i) for i in input().split()]

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

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

Question 2

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

Input is managed for you, please write the required function only.

Input : A list L and an integer n.

Output : First n largest numbers

Solution:

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

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

Question 3

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

Input is managed for you.

Input : A list L

Output : Total number of odd numbers.

Solution:

``````L = [int(i) for i in input().split()]
even_count, odd_count = 0, 0

# iterating each number in list
for num in L :

# checking condition
if num % 2 != 0 :
odd_count += 1

print (odd_count, end = "")``````

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

This is an assignment for The Joy of Computing using Python Week 3 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.

### Correct Slippers: CORRSLP