0% found this document useful (0 votes)
8 views9 pages

Module 4 Worksheet - Copy

Uploaded by

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

Module 4 Worksheet - Copy

Uploaded by

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

Module 4 – Worksheet 1

Multiple Choice Questions

Q.No 1. What is the purpose of the "exchange the values" algorithm?


a) Sorting
b) Searching
c) Factorial Computation
d) Base Conversion

Answer: a) Sorting

Q.No 2. In Python, what is the keyword used for conditional statements with multiple
branches?
a) If
b) else
c) elif
d) switch

Answer: c) elif

Q.No 3. What is the result of the summation algorithm for the input [1, 2, 3, 4]?
a) 10
b) 15
c) 20
d) 25

Answer: a) 10

Q.No 4. Which statement is used for early termination of a loop in Python?


a) Break
b) continue
c) pass
d) exit

Answer: a) Break
Q.No 5. What is the value of the factorial of 5?
a) 120
b) 240
c) 60
d) 480

Answer: a) 120

Q.No 6. The Fibonacci sequence starts with which two initial numbers?
a) 0, 1
b) 1, 2
c) 0, 2
d) 1, 3

Answer: a) 0,1

Q.No 7. Which algorithm is used for reversing a list in Python?


a) Reverse
b) Flip
c) Backtrack
d) None of the above

Answer: a) Reverse

Q.No 8. x = 5
if x > 3:
print("Greater than 3")
elif x < 3:
print("Less than 3")
else:
print("Equal to 3")
a) Greater than 3
b) Less than 3
c) Equal to 3
d) No output

Answer: a) Greater than 3


Q.No 9. The "pass" statement in Python is used for ?
a) Terminating a loop
b) Skipping the current iteration of a loop
c) Creating an empty function or class
d) Exiting the program

Answer: c) Creating an empty function or class

Q.No 10. What is the purpose of the base conversion algorithm?


a) Sorting
b) Changing the data type of a variable
c) Converting a number from one numeral system to another
d) Calculating the power of a number

Answer: c) Converting a number from one numeral system to another


Module 4 – Worksheet 2
Fill in the blanks

Q. No1. The _______ statement in Python is used to iterate over a sequence (e.g., a list or range).

Answer: for

Q.No.2. The _______ function in Python is used to convert a character to its corresponding ASCII
value.
Answer: ord

Q.No.3. The _______ statement in Python is used for repeated execution of a block of code as long as
a certain condition is true.

Answer: while

Q.No.4. The _______ operator in Python is used to test if two values are equal.

Answer: ==

Q.No.5. The _______ statement is used for creating an empty block of code in Python.

Answer: pass

Match the following


PART A PART B ANSWER
(1) Factorial Computation (A) Changing the numeral system of a number Base
Conversion
(2) Iteration (B) Early termination of a loop Iteration

(3) Base Conversion (C) Computing the product of consecutive integers Factorial
Computation
(4) if-elif-else (D) Conditional statements with multiple branches If-elif-else
(5) Reverse (E) Inverting the order of elements in a sequence Reverse
Module 4 – Worksheet 3

Q.No 1 : Write a Python function to calculate the factorial of a given number using recursion.
Solution:

Q.No 2: Implement a Python program to find the sum of the Fibonacci sequence up to the nth
term, where n is provided by the user.
Solution:
Q. No 3 Develop a Python function that reverses a string without using any built-in reverse
function.
Solution:

Q. No: 4. Create a Python program that converts a decimal number to binary using the base
conversion algorithm
Solution:
Q. No: 5. Write a Python function that takes a character as input and returns its ASCII value
using character to number conversion.

Solution:

Q. No: 6. The following Python code is intended to print the sum of all even numbers from 1
to 10. Identify and fix the error

sum_even = 0
for i in range(1, 11):
if i % 2 == 0:
sum_even += i
print("Sum of even numbers:", sum_even)
Solution:
Q. No: 7. There's an error in the following Python code that is supposed to calculate the
factorial of a given number. Identify and correct the error

def factorial(n):
result = 1
for i in range(1, n+1):
result *= i
return result
num = input("Enter a number: ")
print("Factorial:", factorial(num))
Solution:

Q. No 8. The following Python function is meant to reverse a list, but there's an error.
Identify and fix the issue
def reverse_list(lst):
return lst[::-1]
original_list = [1, 2, 3, 4, 5]
reversed_list = reverse_list(original_list)
print("Reversed List:", reversed_list)
Solution:

Q. No 9. This Python program is intended to convert a given decimal number to binary.


However, there's a mistake. Find and correct the error
def decimal_to_binary(decimal):
return bin(decimal)
num = int(input("Enter a decimal number: "))
binary_num = decimal_to_binary(num)
print("Binary equivalent:", binary_num)
Solution:

Q. No 10. The following Python code is intended to check if a given number is positive,
negative, or zero. However, there's a logical error. Identify and fix the issue
num = int(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
Solution:

You might also like