Explain the structure of user defined function in Python.
Illustrate the same with respect
to a function to add two numbers.?
1. Function Definition
Use the def keyword to define a function followed by the function name and parentheses ().
2. Parameters (optional)
You can pass values to the function through parameters inside the parentheses.
3. Docstring (optional)
A string used to describe what the function does (for documentation).
4. Function Body
The block of code that performs the task. It is indented under the function definition.
5. Return Statement (optional)
Used to return a result from the function.
Define a function “fact()” to find factorial of a number. Develop a Python program using
the defined function to print factorial of a number entered by the user.?
Develop a Python program to print all prime numbers within a given range. ?
Differentiate between different standard data types used in Python programming
language with example.?
Summarize the precedence of mathematical operators in Python and illustrate with
an example.?
Develop a Python program that prints the numbers from 1 to 10 using a ‘for’ loop.
Further, write the same program using a ‘while’ loop.?
With syntax, explain import statement in Python.?
the import statement is used to include external modules or libraries into your program so
you can use their functions, classes, and variables.
✅ Purpose of import:
It allows you to reuse code written in other files (modules), including Python's built-in
libraries like math, datetime, etc., or your own custom modules.
Different Types of Flow Control Statements in Python?
1. Conditional Statements 2. Looping Statements
x = 10 for i in range(3):
print("Hello")
if x > 0: count=0
print("Positive") while cont<3:
elif x == 0: print(“hi)
print("Zero") count+=1
else:
print("Negative")
2. Loop Control Statements
for i in range(5): for i in range(5):
if i == 3: if i == 3:
break continue
print(i) # Will print 0 1 2 print(i) # Will skip 3
b) Develop a Python program that prints ‘Hello’ if 1 is stored in spam and prints
‘Howdy’ if 2 is stored in spam and prints ‘Greetings!’ if anything else is stored in spam?
c) Develop a Python program that asks for a name and password of a student in order to
use computer using break and continue statements.?
Explain the different standard data types used in Python programming language with
example.?
Illustrate string concatenation and replication with an example for each.?
1. String Concatenation
Concatenation is the process of joining two or more strings together to form a new string.
2. String Replication
Replication (also called repetition) is the process of repeating a string multiple times.
Write Python programs for the following:
i) To convert degrees Fahrenheit to degree Celsius
ii) To find the factorial of a number?
Differentiate between break and continue statements in Python programming language.?
What are nested loops? Write a Python program to display all the permutations of a three
letter word.?
A nested loop is a loop inside another loop. In Python (and most programming languages),
nested loops are used when you need to perform repetitive operations within other
repetitive operations.
What are nested loops? Write a Python program to display all the permutations of a three
letter word.?
1. str() – Convert to String float() – Convert to Floating-point number
Converts numbers or other types into string Converts an integer or numeric string to a flo
2. int() – Convert to Integer
Converts a float or numeric string into an integer.
(Decimals are truncated, not rounded.)
Show with suitable examples i) Comparison operators ii) Mixing Boolean and comparison
operator?
Write a program to calculate factorial of a number, use the concept of FUNCTIONS to
develop the program.?
Differentiate between local and global variables. Give suitable examples.?
How the for loop along with range function works in python? Illustrate with an example
program.?
the for loop is used to iterate over a sequence (such as a list, tuple, string, or range) and
perform a block of code for each item in the sequence. The range() function is commonly
used with a for loop to generate a sequence of numbers.
for variable in range(start, stop, step):
for i in range(1, 6): # Starts at 1, ends at 5 (6 is not included)
print(i)
What is exception handling? Write a python program to handle zero division error?
Exception handling in Python is a mechanism that allows a program to respond to runtime
errors