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.

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.
Answer –
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.
Answer –
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.
Answer –
def student(name, age):
     print(name, age)

student(“Amit”, 22)

Computer Science Class 12 Notes

  1. Python Revision tour – 1 Class 12 Notes
  2. Python Revision tour – 2 Class 12 Notes Notes
  3. Working with Functions Class 12 Notes
  4. Using Python Libraries Class 12 Notes
  5. File Handling Class 12 Notes
  6. Recursion Class 12 Notes
  7. Idea of Algorithmic Efficiency Class 12 Notes
  8. Data Visualization using Pyplot Class 12 Notes
  9. Data Structure Class 12 Notes
  10. Computer Network Class 12 Notes
  11. More on MySQL Class 12 Notes

MCQ for Class 12 Computer Science Python

  1. Python Revision tour – 1 Class 12 MCQs
  2. Python Revision tour – 2 Class 12 MCQs
  3. Working with Functions Class 12 MCQs
  4. Using Python Libraries Class 12 MCQs
  5. File Handling Class 12 MCQs
  6. Recursion Class 12 MCQs
  7. Data Visualization using Pyplot Class 12 MCQs
  8. Data Structure Class 12 MCQs
  9. Computer Network Class 12 MCQs
  10. More on MySQL Class 12 MCQs

Computer Science Class 12 Questions and Answers

  1. Python Revision tour – 1 Class 12 Questions and Answers
  2. Working with Functions Class 12 Questions and Answers
  3. Using Python Libraries Class 12 Questions and Answers
  4. File Handling Class 12 Questions and Answers
  5. Recursion Class 12 Questions and Answers
  6. Idea of Algorithmic Efficiency Class 12 Questions and Answers
  7. Data Structure Class 12 Questions and Answers
  8. More on MySQL Class 12 Questions and Answers
  9. Computer Network Class 12 Questions and Answers
  10. More on MySQL Class 12 Questions and Answers 

Leave a Comment

error: Content is protected !!