0% found this document useful (0 votes)
48 views10 pages

NPTEL Assignment 3-4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views10 pages

NPTEL Assignment 3-4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Week 3: Assignment 3

The due dat e for submitting this assignm


ent has passed.

Assignment su'bmitted on 2024-08-14, 22:07


1ST
1) Which of the following is/are true statement(s
)?
Lists are used to store multiple values.
One can access element in list by using non
-numeric indices.
Iterating over lists is possible in Python.
We need to specify required size of list while
creating a new list variable.
Yes, the ans wer is correct.
Score: 1
Acc epte d Answers:
Lists are use d to store mul tiple values.
Iterating ove r lists is possible in Python.

2) In the belo w code -

n=
a = []
fo r i in ra ng e( n) :
11 = []
p = 0
fo r j in ra ng e( i):
11 .a pp en d( j)
fo rk in 11:
p+ =l
a. ap pe nd (p )
k= 0
k=0
for 1 in a:
k+=l
print(k)
For what value of n does the program print 21 ?

21

No, the answer is incorrect.


Score: O
Accepted Answers:
(Type: Numeric) 7

3) From the previous question, for what values of n is the number 7 appended to list a.

7
6
✓ 8

./ 9

Yes, the answer is correct.


Score: 1
Accepted Answers:
8
9
4) What does the following code perform ? 1 pain

def mystery(c ontainer):


result=[ ]
for i in range(len (container )):
if i % 2 == 0:
result.app end(conta iner[i] * 2)
else:
result.app end(conta iner[i] + 3)
return result
ft converts any input list into a new list which is filled with some alternative even and odd numbers.
It converts any input list into a new list such that at even indices, the value is a multiple of an even number and at odd indices, the value is either odd
or even number.
ft converts any input list into a new list such that at even indices, the value is multiple of 2 and at odd indices, the value is multiple of 3.
It converts any input list into a new list, which follows no pattern.

Yes, the answer is correct.


Score: 1
Accepted Answers:
It converts any input list into a new list such that at even indices, the value is a multiple of an even number and at odd indices, the value is either odd or
even number.

5) From the previous question, if the option - 1 point


ft converts any input list into a new list which is filled with some alternative even and odd numbers.
is incorrect, Can you make changes to code such that this option is true ?

No, it is not possible to make such changes.


No, the option is already correct.
Yes, we can make changes.

Yes, the answer is correct.


Score: 1
Accepted Answers:
Yes, we can make changes.
6) If file.bet exists, Does the code successfully run ?

• :1
.-. ~: open ("+·
, ~1 ,_ .. t :-: ~ ,• ,
dat a= f.re ad( )
prin t(da ta)
Yes
No

Yes, the answ er is corre ct.


Score: 1
Acce pted Answers:
No

7) Which of the following are examples of Social Computing ?

StackOverflow
Wikipedia
Quora
None

Yes, the answ er is corre ct.


Score: 1
Acce pted Answers:
StackOverflow
Wikipedia
Quora
8) What does the following code print for n = 3?

n =
k = 0
a = []
b = 0
while (n ! = 0):
k = k + (n X 10)
a.append(n % 10)
n = n//10
a. sort()
f'.Jr i 1n a:
b = b + i
::(b == k):
print( "WE KNO\oJ THE WISDOM OF SERIES")
.. l . '=' :
print("Wl: ARE: YET TO KNOW MANY !HING~")

WE KNOW THE WISDOM OF SERIES


WE ARE YET TO KNOW MANY THINGS

Yes, the answer is correct.


Score: 1
Accepted Answers:
WE KNOW THE WISDOM OF SERIES

9) From the previous question, is the variable nor a.sortO responsible for printing of either of the two possible sentences?

No, it is not dependent on variable n, the code will never print "WE ARE YET TO KNOW MANY ~i-JINGS".
Yes on a.sortQ only, but the code will never print "WE ARE YET TO KNOW MANY THINGS".
Yes on both, the code may print both sentences.
No, it is not dependent on a.sortQ, the code will never print "WE ARE YET TO KNOW MANY THINGS".

Yes, the answer is correct.


Score: 1
Accepted Answers:
No, it is not dependent on variable n, the code will nevor print "WE ARE YET TO KNOW MANY THINGS".
No, it is not dependent on a.sort0, the code will never print "WE ARE YET TO KNOW MANY THINGS".

10) What does the code in question 8, calculate ?


2309
Can you say what the values of k and bare if n = 10294343763482 x 10 .

If values of k and bare different, enter 0, else enter value or k

56

answer is correct.
Week 4: Assignment 4
The due date for submitting this assignment has passed.
Due on 2024-08-21, 2

Assignment submitted on 2024-08-21, 20:06 1ST


1) Which of the following options provides the general formula for the magic constant of a magic square of size n, where all elements are distin
numbers from 1 to n2 ?

n(n 2 + 1)
2

n3
2

n3 +2
2

n4 + n2
2n
Yes, the answer is correct.
Score: 1
Accepted Answers:
n(n 2 + 1)
2
n4 + n2
~
2n
2) What would the magic constant be for a magic square of size 6, given that all elements in the square are distinct numbers from 1 to 36?

72
111
109
110

Yes, the answer is correct.


Score: 1
Accepted Answers:
111
3) Does transposing the magic square give us a new magic square ?

Yes
• No

No, the answer is incorrect.


Score: 0
Accepted Answers:
Yes
4) Which of the following are valid magic squares ?

10 3 13 8
5 16 2 11
4 9 7 14
15 6 12 1

20- e 6-e 26- e 16 - e


10 - e 32 - e 4-e 22- e
8-e 18 - e 14- e 28 - e
30 - e 12 - e 24- e 2-e

1 14 4 15
8 11 5 10
13 2 16 3
12 7 9 6

,r 14,r 4,r 15,r


8,r ll,r 5,r 10,r
13n 2n 16,r 3n
12n 7n 9n 6n
Yes, the answer is correct.
Score: 1
Accepted Answers:
IO 13 8
3
5 16 2 I1
4 9 7 14
15 6 12
20 - e 6-e 26 - e 16 _ el
r 10 - e 32 - e 4-e 22 - e
5) What is the minimum number of people required to ensure that at least two of them share the same 30-minute
birth interval? The intervals start from
12:00 AM and each interval lasts for half an hour.

49

Yes, the answer is correct.


Score: 1
Accepted Answers:
(Type: Numeric) 49

1 point
6) Calculate the magic constant for 4x4 square, where all elements are distinct numbers from 1 to 16, is it same as
the magic constant for Ramanujan's
magic square ?

If yes, enter 0, else enter the absolute difference between the two.
Hint: Search the about Ramanujan's magic square.

105

Yes, the answer is correct.


Score: 1
Accepted Answers:
(Type: Numeric) 105
7) What task does function1 Operform ?

function l{numbe r):


listl = []
for i in range(l , number):
if number% i == 0:
listl.ap pend{i)
return listl

def functio n2(nl, n2):


flag= False
list2 = []
for i in functio nl(nl):
for j in function l(n2):
if i == j:
flag= True
list2.ap pend(i)
if len(list 2) > 0:
print("C omplete d")
Calculate factorial of number n.
Calculate factors of number n.
Calculate prime factors of number n.
Calculate factors of number n excluding n.

Yes, the answer is correct.


Score: 1
Accepted Answers:
Calculate factors of number n excluding n.
8) For what n1 ,n? flag will the variable flag inside function20 be not equal to true ?

2,3
0,0
1,1
1,0

Yes, the answer is correct.


Score: 1
Accepted Answers:
0,0
1, 1
1,0

9) If all possible pairs of prime numbers between 0 and 20, are given to n1 and n2, for how many pairs would function2 print "Completed" ? 1

It will not print "Completed" for any pair.


It will print "Completed" only for pairs (2,3)(3,5),(2,5), and for the remaining it would not print "Completed".
It will print "Completed" only for pair (2,3), and for the remaining other pairs of primes it would not print "Completed".
It will print "Completed" for all pairs of primes between 0 and 20.

Yes, the answer is correct.


Score: 1
Accepted Answers:
It will print "Completed" for all pairs of primes between O and 20.

10) If numbers of pairs of primes which result in function2 to print "Completed" are greater than 0, Can we edit the code in function20 so that " 1
Completed" is never printed for any pair of primes ?

Yes, we can change the logic for setting flag variable to True.
Yes, we can change/increase the threshold for length of list2 in the last if block.
No, it is logically not possible.
Yes, we can change the initial value of flag to True, instead of False.

Yes, the answer is correct.


Score: 1
Accepted Answers:
Yes, we can change/increase the threshold for length of list2 in the last if block.

You might also like