# Working with Functions in Python Class 12 Solutions

Teachers and Examiners (CBSESkillEduction) collaborated to create the Working with Functions in Python Class 12 Solutions. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.

Contents

## Working with Functions in Python Class 12 Solutions

1. What do you understand by local and global scope of variables? How can you access a global variable inside the function, if function has a variable with same name.
Answer – A global variable is a variable that is accessible globally. A local variable is one that is only accessible to the current scope, such as temporary variables used in a single function definition. A variable declared outside of the function or in global scope is known as global variable. This means, global variable can be accessed inside or outside of the function where as local variable can be used only inside of the function. We can access by declaring variable as global A.

2. What is the deference between local variable and a global variable?
Answer – Local variables have a scope that is limited to the function in which they are defined, whereas global variables have a scope that encompasses the entire programme.

3. Differentiate between the round() and floor() functions with the help of suitable example.
Answer – The function floor() is used to convert to the lowest lower whole number, whereas the function round() is used to convert a fractional number into a whole as the nearest next. For example, round (5.8) = 6, round (4.1) = 5, and floor (6.9) = 6, floor (5.01) = 5.

4. What is the difference between input() and raw_input()?
Answer – In Python, raw input() and input are two functions that can be used to read data or input from the user (). The outcomes can be kept in a variable. raw input(): This function returns a string after reading the command or input. Python types like list, tuple, int, etc. are returned by the input() function after reading the input.

5. What is a function?
Answer – A function in computer programming is a chunk of code with a name that carries out a particular activity. Usually, this entails receiving some input, processing it, and then producing an

6. Write and explain the types of functions supported by python.
Answer – In Python, there are two categories of functions: User-Defined Functions: The user can define these types of functions to carry out any particular task. Built-in Functions are pre-defined functions that are available in Python.

7. Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n=int(input(“Enter Number : “))
print(factorial(n))

8. Write a Python function to find the Max of two numbers.
def myfunction( x, y ):
if x > y:
return x
return y

print(myfunction(2, 5))

9. Write a program to create a function that takes two arguments, name and age, and print their value.