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

Python Programming Exam for AI Students

This document outlines the internal examination for the Programming with Python course at Arunachala Arts & Science College. It includes multiple-choice questions, short answer questions, and an explanation of key programming concepts such as function calls, recursion, and the return statement. The answer key is also provided for the exam questions.

Uploaded by

sheebugeethu
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 views3 pages

Python Programming Exam for AI Students

This document outlines the internal examination for the Programming with Python course at Arunachala Arts & Science College. It includes multiple-choice questions, short answer questions, and an explanation of key programming concepts such as function calls, recursion, and the return statement. The answer key is also provided for the exam questions.

Uploaded by

sheebugeethu
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

ARUNACHALA

ARTS & SCIENCE (WOMEN)COLLEGE


‘Kanakammal Gardens’,Vellichanthai,
Kanyakumari District - 629 203.
[Affiliated to Manonmaniam Sundaranar University, Tirunelveli.]

Department of Artificial Intelligence

Internal Examination-II

Programming with Python

Class: II [Link]. (AI) Date: 2025


[Link]
Duration:1Hrs

Part-A (2×1=2)

I Choose the Correct Answer


1. In Python, indentation is used to:
a) define blocks of code b) indicate end of a statement c) write comments d) None of the above

2. Which keyword is used to create a function in Python?


a) func b) define c) def d) function

Part-B (2×5=10)

II Answer the following Questions


[Link] is a function call? Explain with an example.
4. Define recursion. Explain with an example.

Part-C (1×8=8)

III Answer the following Question

5. What is the purpose of the return statement in Python? Illustrate


with an example.
Answer Key -Internal Exam II

Part-A

1. a) define blocks of code


2. a) func

Part B

3. A function call is the process of invoking (executing) a function that has been defined earlier in a Python
program. When a function is called, the control of the program is transferred to that function, the
statements inside it are executed, and then control returns to the main program.

Syntax of Function Call


function_name(arguments)
function_name → the name of the defined function.
arguments → the values passed to the function (optional).

Step 1: Define a function


def greet(name):
print ("Hello,", name)
Step 2: Call the function
greet("Alice”) # Function call

 The function greet () is defined to take one argument name.


 The line greet("Alice") calls the function and passes "Alice" as an argument.
 The function executes and prints "Hello, Alice".

Example with Return Value


def add (a, b):
return a + b

result = add (5, 3) # Function call


print ("Sum:", result)
Output:
Sum: 8
Here, add (5, 3) is the function call that returns a value to the variable result.

4. Recursion is a programming technique where a function calls itself to solve a problem. Each recursive call
should bring the problem closer to a base case, which stops the recursion.

Basic Structure of Recursion


def recursive_function(parameters):
if base_condition:
return result
else:
return recursive_function(modified_parameters)
Example: Factorial of a Number
The factorial of n (written n!) is: n! = n × (n-1) × (n-2) × ... × 1

Recursive Implementation:
def factorial(n):
if n == 0 or n == 1: # Base case
return 1
else:
return n * factorial(n - 1) # Recursive case
print(factorial(5)) # Output: 120

Example: Fibonacci Sequence


Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, ... Each number is the sum of the two preceding ones.
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
print(fibonacci(6)) # Output: 8

Part-C

5. The return statement in Python is used inside a function to:

 Send a value back to the caller of the function


 Terminate the function immediately
 Optionally return multiple values (as a tuple)

Example
def add_numbers(a, b):
result = a + b
return result # returns the sum to the caller

sum_value = add_numbers(5, 3)
print(sum_value)

Explanation

 The function add_numbers computes a + b.


 The return result statement sends the computed value back.
 sum_value receives 8, which is printed.

If you remove return, the function will return None.

You might also like