2marks Question Bank (Model)
2marks Question Bank (Model)
Algorithm:
Step 1: Start.
Step 2: Read a, b . / * a, b two numbers */
Step 3: If a>b then /*Checking */
Display “a is the largest number”.
Otherwise.
Display “b is the largest number”.
Flowchart:
amount of time.
solutions to a
Step 1: Start
Step 4: Add num1 and num2 and assign the result to sum.
S sum=num1+num2
For loop
While loop
UNIT 2
operations.
# dd/mm/YY H:M:S
Operator: +,=
Operand: sum,a,b
Unit 3
def sumOfSeries(n):
sum = 0
for i in range(1, n + 1):
sum += i * i*i
return sum
n=5
print(sumOfSeries(n))
1. While Loop
2. For Loop
while (condition):
statements
statements
The function will print the local x, and then the code will print
the global x:
output:
200
300
Advantages of recursion
Disadvantages of recursion
a=[20,30,40,50,60,70,89]
print(a)
if(search==a[i]):
break
else:
print("not found")
output
element found at 2
UNIT 4
List items are indexed, the first item has index [0], the second
item has index [1] etc.
Difference:
2.Give a function that can take a value and return the first
key mapping to that value in a dictionary.
numbers = [1, 2, 3, 4, 5]
squared = [x ** 2 for x in numbers]
print(squared)
Unit 5
Built-in Modules:
Python comes with a set of built-in modules that
provide essential functionalities.
math: Mathematical functions.
os: Operating system interfaces.
sys: System-specific parameters and functions.
datetime: Date and time manipulation.
Third-party Modules: Developers often create and share
reusable code in the form of third-party modules. These can be
installed using package managers like pip.
numpy: Numerical computing with arrays.
requests: HTTP library for making web requests.
pandas: Data manipulation and analysis.
matplotlib: Plotting and data visualization.
Custom Modules: Developers can organize their code by
creating custom modules. example, if you have a file named
my_module.py with a function my_function, you can import it
using import my_module and then use
my_module.my_function().
The arguments that are given after the name of the program in the
command line shell of the operating system are known as Command Line
Arguments. Python provides various ways of dealing with these types of
arguments. The three most common are:
Using sys.argv
Using getopt module
Using argparse module
.