The Joy of Computing using Python Week-4

Quiz Week 4: Assignment 4

Solution

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 distinct numbers from 1 to n?

Answer: [Option 1] n(n2+1)/2 & [Option 4] (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? 

Answer: [Option 2] 111

3. Does transposing the magic square give us a new magic square ?

AnswerNo

4. Which of the following are valid magic squares ?

Answer[Option 1], [Option 3], [Option 4] 

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.

Answer: 49

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 ?

Answer: 105

7. What task does function1() perform ?

Answer[Option 4] Calculate factors of number n excluding n.

8. For what n1,n2 flag will the variable flag inside function2() be not equal to true ?

Answer[Option 2](0,0)[Option 3](1,1)[Option 4](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” ?

Answer: [Option 4] It will print all pairs of primes between 0 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 function2() so that ”Completed” is never printed for any pair of primes ?

Answer:  [Option 2] Yes, we can change/increase the threshold for length of list2 in the last if block. 

Discussion makes the solution more accurate ( social computing ) discuss the solution in comments. Do share this with your friends !! Comment the queries, I will reach out to you.
Week 4 programming assignment solution coming soon ☺......

Comments

Popular posts from this blog

The Joy of Computing using python -Week 1