0% found this document useful (0 votes)
6 views1 page

Python Programming Exam Paper I-B.Sc CS

study material

Uploaded by

velu
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)
6 views1 page

Python Programming Exam Paper I-B.Sc CS

study material

Uploaded by

velu
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

GOVERNMENT ARTS and SCIENCE COLLEGE, IDAPPADI GOVERNMENT ARTS and SCIENCE COLLEGE, IDAPPADI

SECOND INTERNAL EXAMINATION SECOND INTERNAL EXAMINATION

CLASS: [Link] (CS) Python Programming Total Marks : 50 CLASS: [Link] (CS) Python Programming Total Marks : 50
Date: 22.09.2023 Paper Code: 23UCSCC01 Time : 2 hrs
Date: 22.09.2023 Paper Code: 23UCSCC01 Time : 2 hrs
SECTION – A (5×1=5)
SECTION – A (5×1=5)
1. Which keyword is used for function?
1. Which keyword is used for function?
a) Fun b) Define c) def d) Function
a) Fun b) Define c) def d) Function
2. What is called when a function is defined inside a class?
2. What is called when a function is defined inside a class?
a. class b. function c. method d. module
a. class b. function c. method d. module
3. What is a recursive function?
3. What is a recursive function?
a. A function that calls other function. b. A function which calls itself.
a. A function that calls other function. b. A function which calls itself.
c. Both A and B d. None of the above
c. Both A and B d. None of the above
4. What is a variable defined outside a function referred to as?
4. What is a variable defined outside a function referred to as?
a. local variable b. global variable
a. local variable b. global variable
c. static Variable d. automatic variable
c. static Variable d. automatic variable
5. A return statement with _____ arguments.
5. A return statement with _____ arguments.
a. No b. 1 c. 2 d. Any
a. No b. 1 c. 2 d. Any
SECTION – B (3×5=15)
SECTION – B (4×5=15)
6. Various jumping statements in python.
6. Various jumping statements in python.
7. Describe about recursive function with an example..
7. Describe about recursive function with an example..
8. Explain about keyword arguments in python.
8. Explain about keyword arguments in python.
SECTION – C (3×10=30)
SECTION – C (5×10=50)
9. Explain in detail about looping statements.
9. Explain in detail about looping statements.
10. Explain in details about various String handling function .
10. Explain in details about various String handling function .
11. Write a python program to generate mark statement with different
11. Write a python program to generate mark statement with different
function names as basic, marks and result
function names as basic, marks and result
******* All the Best *******
******* All the Best *******

Common questions

Powered by AI

Python uses the 'def' keyword to define functions, which includes specifying the function name and its parameters within parentheses. This keyword indicates the creation of a block of code that can be executed later by invoking the function name. Once defined, the function name is bound to the function body, allowing it to be referred to by that name throughout the program. This mechanism promotes code reusability and modularity, as the defined function can be reused wherever required by simply calling it with the appropriate arguments .

Recursive functions in Python are functions that call themselves during execution. They are used to solve problems that can be broken down into smaller, similar problems, known as divide and conquer strategy. A key characteristic of a recursive function is that it must have a base case to prevent infinite recursion. An example of a recursive function is the calculation of the factorial of a number: `def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)`. Here, `factorial(0)` provides the base case, returning 1 to stop further recursive calls .

Using Python's return statement with no arguments allows a function to exit without returning a value, implicitly returning `None`. This is particularly advantageous for functions that perform actions without needing to provide output, such as modifying global variables or input/output operations. Compared to explicitly returning a value, this approach emphasizes that the primary goal of the function is the side effect rather than the result. However, when output is needed from a function, returning specific values is essential for further processing .

In Python, the distinction between methods and functions lies in their association with objects. Methods are functions defined within a class and are associated with class instances, meaning they can operate on data contained within the object; they implicitly take the instance as their first parameter, typically named `self`. For example, in a class `Car`, `def drive(self)` is a method. Functions, on the other hand, are standalone blocks of code that perform a specific task and do not belong to any object context. This distinction is significant as methods provide a mechanism for defining behaviors and operations that are specific to the data structures they interact with, facilitating object-oriented programming .

To create a structured Python program for generating a student mark statement, the program can be divided into functions such as `basic()`, `marks()`, and `result()`. The `basic()` function can handle the input of student details. The `marks()` function can input or calculate marks for each subject, and the `result()` function can calculate the total and determine pass/fail status. This modular design enhances readability and maintainability. For instance: `def basic(): name = input('Enter student name: ') def marks(): return {'Math': 90, 'Science': 85} def result(marks): total = sum(marks.values()) return 'Pass' if total/len(marks) > 40 else 'Fail' .

Local variables are those defined within a function and have a scope limited to that function, meaning they cannot be accessed outside of it. For example, in `def foo(): x = 20`, `x` is a local variable. Global variables, on the other hand, are defined outside any function and can be accessed from any part of the program. For example, `y = 100` defined outside functions can be used anywhere. To modify a global variable inside a function, the `global` keyword is used .

String handling functions in Python provide a range of methods for string manipulation, making it easier to process and modify string data. Key functions include `len()`, which returns the length of a string; `str.upper()` and `str.lower()`, which convert strings to uppercase and lowercase respectively; `str.find()`, which locates a substring; and `str.replace()`, which replaces occurrences of a substring with another substring. For example, `"hello".upper()` transforms the string to "HELLO", and "hello world".replace("world", "Python") changes the string to "hello Python". These functions make handling strings straightforward and consistent .

Keyword arguments in Python allow you to specify argument values in a way that makes the function calls more readable by explicitly associating values with the parameter names, rather than relying on their positions. This improves code clarity and reduces errors, especially in functions with many parameters, as you don't need to worry about remembering the order of parameters. Also, keyword arguments enable functions to be called with default parameters more flexibly. This contrasts with positional arguments, where the order determined the argument association, often leading to mistakes in complex functions .

In Python, jumping statements are used to alter the flow of control in the program, and these include `break`, `continue`, and `pass`. The `break` statement terminates the loop execution and transfers control to the statement immediately following the loop. It is often used in loops to exit the loop when a certain condition is met. The `continue` statement skips the rest of the code inside the loop for the current iteration and jumps to the next iteration, useful for skipping specific loop cycles. The `pass` statement does nothing and is used as a placeholder for future code .

Looping statements in Python are constructs that enable repeated execution of a block of code as long as a specific condition is met. There are mainly two types of loops: `for` and `while`. The `for` loop iterates over a sequence (such as a list, string, or range) and executes the block of code a set number of times. For example, `for i in range(5): print(i)` will print numbers 0 to 4. The `while` loop continues to execute the block of code as long as the given condition is `True`, for example, `while x < 5: x += 1`. Proper use and understanding of these loops enable efficient problem-solving in programming .

You might also like