0% found this document useful (0 votes)
2 views

selfstudys_com_file (5)

The document provides a series of questions and answers related to functions in Python, covering built-in mathematical functions, arguments, return values, and variable scopes. It includes examples for differentiating between positional and default arguments, parameters and arguments, and global and local variables. Additionally, it presents several function definitions that demonstrate how to check for positive/negative numbers, determine even/odd status, compute string length, and sum a list of integers.

Uploaded by

aadi03409
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

selfstudys_com_file (5)

The document provides a series of questions and answers related to functions in Python, covering built-in mathematical functions, arguments, return values, and variable scopes. It includes examples for differentiating between positional and default arguments, parameters and arguments, and global and local variables. Additionally, it presents several function definitions that demonstrate how to check for positive/negative numbers, determine even/odd status, compute string length, and sum a list of integers.

Uploaded by

aadi03409
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TOPIC - FUNCTIONS IN PYTHON

Q.No Question Answer


SECTION -I-PART A 1 mark question
1. Name the built-in mathematical function / method abs
that is used to return an absolute value of a number.

2. Name the built-in mathematical function / method max


that is used to return maximum value in a list
3. Name the built-in mathematical function / method min
that is used to return min value in a list
4. Name the built-in mathematical function / method round
that is used to round the numbers
5. Mention the output of the following Python function: 4
len(["hello",2,4,6])
6. Name the key word used for defining a function def

SECTION -I-PART B 2 marks


7. Differentiate between Positional Positional arguments are arguments that can be
Argument and Default Argument of called by their position in the function
function in python with suitable definition.
example Python allows function arguments to have
default values; if the function is called without
the argument, the argument gets its default
value.
def function(a, b, c):
print(a,b,c)
A positional argument is passed to the function
in this way.

function(1,2,3)
will print
123

def function(a, b, c=3):


print(a,b,c)

function(1,2)
will print
123
8. What is the meaning of return value The Python return statement is a special
of a function? Give an example to statement that you can use inside a function or
illustrate its meaning. method to send the function's result back to the
caller. A return statement consists of the return
keyword followed by an optional return value.
def calc_sum(a,b):
return a+b
sum_val=calc_sum(2,3)
print(sum_val)

This program will print:


5

9. Deferentiate between parameters A parameter is the variable listed inside the


and arguments in Python. Mention a parentheses in the function definition. An
suitable example argument is the value that are sent to the
function when it is called.
def calc_sum(a,b):
return a+b
sum_val=calc_sum(2,3)
print(sum_val)

Here calc_sum(a,b) -> a and b are parameters


calc_sum(2,3) -> 2 and 3 are arguments
10. Mention the output: Hello
def print_hello(): Hello
print("Hello")
print_hello()
print_hello()
11. Differentiate between Global and Local variables can be accessed only inside the
Local variable with a suitable example function in which they are declared, whereas
global variables can be accessed throughout the
program body by all functions
x=10
def local_chk():
y=5
Here x is global variable and y is local variable.

SECTION -II 3 marks


12. Write a function check_pos_neg(num) def check_pos_neg(num):
which takes a number from the user if num==0:
and prints whether the number is print("The number is Zero")
Zero or positive or negative elif num <0:
print("The number is Negative")
else:
print("The number is Positive")
num=int(input("Enter a number:"))
check_pos_neg(num)
13. Write a function even_odd(num) def even_odd(num):
which takes a number and checks if num%2==0:
whether the number is even or odd print("Number is even")
else:
print("Number is odd")
num=int(input("Enter the Number:"))
even_odd(num)
14. Write a function compute_len(strinp) def compute_len(strinp):
which takes a string and returns the return len(strinp)
length of the string str_a=input("Enter the String:")
compute_len(str_a)
15. Write a function comp_sum(lista) def comp_sum(lista):
which takes a list of integers and total=0
return the sum for i in lista:
total+=i
return total
listinp=eval(input("Enter list:"))
print(comp_sum(listinp))

You might also like