The Joy of Computing Using Python JAN-2025
The Joy of Computing Using Python JAN-2025
JAN-2025 Assignment
Week 1 Assignment
Q1. Which blocks can be used to move the cat?
A) Walk
B) Move
C) Teleport
D) Glide
2. Which set of blocks moves the cat 40 steps and then points down?
4. From the previous question, what is the value of myNum after the loop ends?
A) 1
B) 2
C) 7
D) 0
5. Let the answer from the previous question be stored in variable x. What does the cat say after the
execution of the loop?
A) 16
B) 5
C) 29
D) 2
6. Which of the following data types is primarily used for storing a sequence of characters in most
programming languages?
A) Integer
B) Float
C) String
D) Boolean
7. Which of the following statements best describes why loops are commonly used?
8. Suppose you have an arithmetic expression involving addition, subtraction, multiplication, and
exponentiation. Which statement is true about instructing a computer to evaluate it?
A) Moves the ball in a parabolic path and stops 18 steps away from the center (0, 0) in the x-direction.
B) Moves the ball in a circular path 18 times.
C) Moves the ball in a parabolic path and stops 18 steps away from the center (0, 0) in the y-direction.
D) Moves the ball in a parabolic path and stops 17 steps away from the center (0, 0) in the x-direction.
Week 2 Assignment
Q1. Statement: If a variable is assigned a value once, the value in the variable cannot be changed in the
variable.
Q2. Which of the following code blocks prints – “Ramesh talks to Suresh and Kamlesh”?
Q3. What aren’t the correct ways to inform Python that input is a decimal point number?
a. in(input())
b. float(input())
c. int(input())
d.a = input()
a = int(a)
a. 1
b. 2
c. 6
d. 5
a. while loop
b. for loop
c. do-while loop
d. while-range loop
Q7. What happens when the condition inside the if and while evaluate to false?
a. Python interpreter ignores the if/while blocks and halts the program.
b. Python interpreter ignores the if/while blocks and proceeds with the program from the lines after
the if/while block.
c. Python interpreter executes the if/while blocks and the rest of the program.
d. Python interpreter executes the if/while blocks, and the program runs in an infinite loop.
Q8. The following program might/might not have an infinite loop. Does the program have an infinite loop?
a. aryan, 20
b. arjun, 19
c. aakash, 16
d. anand, 18
Q10. For which of the options from the previous question does the program not print anything?
a. aryan, 20
b. aakash, 16
c. arjun, 19
d. anand, 18
Week 3 Assignment
1) Which of the following is/are false statement(s)?
a) Lists are fixed in size; they cannot store more than 1024 values.
b) One can access elements in a list using non-numeric indices.
c) Iterating over lists is possible in Python.
d) We need to specify the required size of a list while creating a new list variable.
ANS- 5
3) From the previous question, for what values of nn is the number 25 appended to list a?
a) 25
b) 24
c) 35
d) 32
4) What does the following code perform?
a) It converts any input list into a new list which is filled with some numbers that are always in
increasing order.
b) 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 even or a negative number.
c) It converts any input list into a new list such that at odd indices, the value is always an even
number and at even indices, the value is negative.
d) It converts any input list into a new list, which follows no pattern.
“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 even or a negative number.”
is incorrect, can you make changes to the code so that this option is always true for any input?
a) Yes
b) No
a) ChatGPT
b) Wikipedia
c) Quora
d) Twitch
8) What does the following code print for n=2560n = 2560?
a) PYTHON IS BORING
b) PYTHON IS FUN
9) From the previous question, is a.sort() responsible for printing either of the two possible sentences?
If the values of kk and bb are different, enter 0; else, enter the value of kk.
Ans - 57
Week 4 Assignment
Q1. 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²?
a) n(n² + 1) / 2
b) n³ / 2
c) n³ + 2n²
d) (n⁴ + n²) / 2n
Q2. What would the magic constant be for a magic square of size 7, given that all elements in the square
are distinct numbers from 1 to 49?
a) 260
b) 111
c) 175
d) 165
Q3. Does transposing any magic square change the sum across some rows/columns/diagonal?
a) Yes
b) No
Ans - a, c, d
Q5. What is the minimum number of people required to ensure that at least three of them share the same
30-minute birth interval? The intervals start from 12:00 AM, and each interval lasts for half an hour.
Ans. 97
Q6. Calculate the magic constant for a 5×5 square, where all elements are distinct numbers from 1 to 25.
Is it the same as the magic constant for Ramanujan’s magic square?
If yes, enter 0, else enter the absolute difference between the two.
Hint: Search about Ramanujan’s magic square.
Ans. 74
Q8. For what n1, n2 will the variable flag inside mystery2() be equal to True?
a) 1,2
b) 2,3
c) 3,4
d) 0,0
Q9. If all possible pairs of prime numbers between 0 and 10 are given to n1 and n2, for how many pairs
would mystery2() print “Completed”?
a) It will print “Completed” only for pairs (2,3), (7,2), (2,5), and for the remaining it would not print
“Completed”.
b) It will print “Completed” only for pair (2,3), and for the remaining other pairs of primes, it would not
print “Completed”.
c) It will print “Completed” for all pairs of primes between 0 and 20.
d) It will not print “Completed” for any pair.
Q10. If the number of pairs of primes that result in mystery2() printing “Completed” is lesser than 1, can we
edit the code in mystery2() so that “Completed” is always printed for any pair of primes?
a) Yes, we can change the logic for setting the flag variable to False.
b) No, it is logically not possible.
c) Yes, we can change/decrease the threshold for the length of list2 in the last if block.
d) Yes, we can change the initial value of flag to False instead of True.
Week 5 Assignment
Q1. Which of the following is the correct way to add data with key as CS102 and value as “Database
Management Systems” to a dictionary named courses?
Q2. What is the probability of Monty not opening the door with a goat, given the hypothesis that you initially
chose the door which has a car?
a) 0
b) 0.5
c) 1
d) 0.33
Q3. What should be replaced with ? in line 10, so that there is a high chance that final_choice is equal to
2?
a) 2
b) 2**(1024) % 2 != 0
c) 2*(2**(89) + 7) % 2 == 0
d) (2**(90)) % len(doors) != 1
Q4. Given that you have a sorted list of 2048 elements, what is the maximum number of comparisons to
search such an element using linear search? Can binary search do it in fewer comparisons?
a) Yes, binary search can do it more efficiently, linear search takes 1024 comparisons
b) Yes, binary search can do it more efficiently, linear search takes 2048 comparisons
c) No, binary search may/may not do it more efficiently, linear search takes 1024 comparisons
d) No, binary search will take more comparisons, linear search takes 2048 comparisons
Q5. What is the primary use of a file with a .wav or .wave extension?
Q7. In binary search, the list gets divided in every iteration to find the element.
a) True
b) False
Q8. Which of the following are requirements for binary search to work correctly?
Q9. Given an array [4, 2, 7, 1, 3], what will be the array after the third pass of Bubble Sort?
a) [1,3,2,4,7]
b) [2,4,1,3,7]
c) [1,2,3,4,7]
d) [2,1,3,4,7]
Q10. How many swaps are performed in iteration 3 for bubble sorting the list [5,4,3,2,1]? Enter 0 if the list
is sorted in less than 3 iterations.
Ans - 2
Week 6 Assignment
Que. 1 If nn is a positive integer, what is the output of the function given input nn?
def mystery(n):
if n <= 0:
return 0
return n + mystery(n - 1)
Que. 2 Assertion (A): If a recursive function doesn’t have a base case, it may never stop.
Reason (R): Recursion means that a function calls itself.
a) Both (A) and (R) are true, and (R) is the correct explanation of (A).
b) Both (A) and (R) are true, but (R) is not the correct explanation of (A).
c) (A) is true, but (R) is false.
d) (A) is false, but (R) is true.
a) Error
b) 25
c) 26
d) 5
Que. 4 In English, the letter ‘z’ usually appears far less often than most letters. Now imagine applying a
Substitution Cipher to a large body of English text, where ‘z’ is replaced by ‘r’, and every other letter is also
mapped to a unique letter. After encryption, which letter is likely to be the least frequent in the new text?
a) z
b) r
c) e
d) It is not possible to determine
Que. 5 If you have a large ciphertext produced by a simple substitution cipher on an English text, can you
determine the original message by examining how often each letter appears?
Que. 6 Suppose you suspect that a piece of ciphertext was produced using a simple substitution cipher.
Under which circumstances might frequency analysis fail to yield accurate results?
a) Both (A) and (R) are true, and (R) is the correct explanation of (A).
b) Both (A) and (R) are true, but (R) is not the correct explanation of (A).
c) (A) is true, but (R) is false.
d) (A) is false, but (R) is true.
Que. 9 Which outcome generally follows from providing a proper base case in a recursive function?
a) The function returns a predefined result when the base condition is met.
b) It prevents infinite recursion and stops when a specific condition is met.
c) It ensures recursion depth is always constant.
d) It allows the function to keep calling itself indefinitely
Que. 10 In a standard 3×3 Tic-Tac-Toe board, how many distinct winning lines (rows, columns, or
diagonals) pass through the center square?
a) 3
b) 2
c) 5
d) 4
Week 7 Assignment
Q1. What will be the output of the following code?
a) 2
b) 3
c) 4
d) Error
a) 1, 2, 3, 7, 11, 10, 9, 5, 6
b) 1, 2, 3, 5, 6, 7, 9, 10, 11
c) 1, 5, 9, 10, 11, 7, 3, 2, 6
d) 1, 5, 9, 2, 6, 10, 3, 7, 11
Q3. What type of triangle is drawn by the given code?
a) Scalar triangle
b) Right angle triangle
c) Equilateral triangle
d) Isosceles triangle
Ans. b
Q5. What will be the output of the following code?
Ans . d
Q7. Which turtle command is equivalent to lifting up a pen?
a) penlift()
b) penup()
c) uppen()
d) penremove()
a) To improve readability.
b) To reuse code blocks.
c) For the ease of code debugging.
d) All of the above.
a) PIL
b) Imageview
c) IMG
d) image
Q10. In Snakes and Ladders, what can be the ways to track ladders and snakes?
a) 1, 2, 3, 4, 5
b) 5, 4, 3, 2, 1
c) 5, 4, 3, 2
d) 1, 2, 3, 4
6) What will be the effect of the following Python code on the graph?
a) The graph will go up when guess and pick are the same.
b) The graph will go down when guess and pick are the same.
c) The graph will go up when guess and pick are not the same.
d) Both (b) and (c)
7) What is the primary advantage of using tokenization in Natural Language Processing (NLP)?
string = 'hey!there'
a = sorted(string)
a.reverse()
print(a)
9) While converting an image into black and white, can it be converted back into a colored image?
a) True
b) False
a. By matching handwriting
b. By analyzing word length with previous books
c. By analyzing the number of pages in a book
d. By analyzing the book’s preface
2. What is the key difference between lists and tuples in Python, and when would you choose one over the
other?
a. Lists are immutable and can be used when elements need to be modified, while tuples are
mutable and best for storing fixed data.
b. Lists are mutable and can be used for dynamic data manipulation, while tuples are immutable
and used to store fixed collections of items.
c. Both lists and tuples are mutable and can be used interchangeably for any purpose.
d. Tuples are used only for string data, while lists can store any data type.
a. True
b. False
a. 10
b. 8
c. 6
d. 4
6. Which of the following is always true for a connected undirected graph with at least one edge?
7. What is the primary difference between using single quotes, double quotes, and triple quotes to create
strings in Python?
a. Single and double quotes can only be used for single-line strings, while triple quotes are used for
multi-line strings
b. Single quotes are used for strings with one word, while double quotes are for strings with multiple
words
c. Double quotes are more efficient than single quotes for creating strings
d. There is no difference in how Python interprets single quotes, double quotes, or triple quotes for
strings
8. How many nodes and edges does the following graph have?
a. 10,6
b. 10,5
c. 8,6
d. 8,5
9. A complete graph will have a degree of separation?
a. 1
b. 2
c. 3
d. Depends on the number of nodes
a) toPmiagmnrh
b) toPmiagmnrPg
c) tnoaigmooP
d) toPmiagmnr
a) 6
b) 7
c) 9
d) Value Error
print(17 % -5)
a) 3
b) 2
c) 0
d) -3
6. Which method in PIL is used to resize an image while maintaining the aspect ratio?
a) resize()
b) thumbnail()
c) reshape()
d) aspect ratio resize()
7. Which of the following correctly finds all numbers divisible by 3 but not by 5 in a list?
a) 2
b) 5
c) [5, 6]
d) 4
9. For which value of axis the output is [5, 7, 9] in the below code?
a) 0
b) 1
c) 2
d) axis argument is not required.
10. What will be the shape of the resulting NumPy array?
a) (3, 2)
b) (4, 3)
c) (3, 4)
d) (4, 2)
Week 11 Assignment
Q1. In Selenium, what is the purpose of WebDriver, such as webdriver.Chrome()?
It is used to interact with web elements like buttons and text fields.
It launches and controls a web browser session for automation.
It is used to write test cases in Selenium.
It provides built-in methods to handle databases in web applications.
Q2. Which of the following is the best locator strategy in Selenium in terms of performance?
find_element_by_name()
find_element_by_id()
find_element_by_class_name()
find_element_by_xpath()
Q3. Selenium WebDriver can be used to automate both web and native mobile applications on Android
and iOS.
True
False
Checking 3
Checking 8
Checking 1
Found at index 3
Checking 3
Checking 1
Found at index 3
Checking 3
Checking 8
Checking 1
Checking 7
Found at index 3
Found at index 3
False
True
None
1
2024-02-30
2024-03-01
ValueError
2024-02-29
Q8. Which function is used to get the current local time in Python?
time.localtime()
datetime.now()
time.time()
datetime.utcnow()
Q9. What happens when you apply .astimezone() to a naive datetime object?
It changes to UTC
It raises an error
It assumes local timezone
It converts to IST
Q10. What is the output of the following Python code?
G.degree(node)
G.get_degree(node)
G.node_degree(node)
G.find_degree(node)
Q3. Observe the following graph generated using the networkx module. How many edges does this graph
contain?
6
7
8
9
Ladder Graph
Barbell Graph
Wheel Graph
Star Graph
(4, 4)
(4, 8)
(4, 2)
(8, 4)
Q7. What is the output of this code?
7
16
5
10
Depth-First Search
Hyperlink Analysis
Random Walk Simulation
Data Scraping
Q10. In the PageRank algorithm, what happens when a page receives multiple inbound links from highly
ranked pages?