Gu 5th sem bca python programming solved question paper 2023
Gu 5th sem bca python programming solved question paper 2023
1. Numeric Types:
2. Sequence Types:
3. Mapping Type:
4. Set Types:
5. Boolean Type:
6. NoneType:
Answer:
Command-line arguments are inputs passed to a Python script during its
execution via the command line. These arguments are stored in the
sys.argv list, where:
Example:
python
Copy code
import sys
print(sys.argv)
Copy code
Copy code
Answer:
A class in Python is a blueprint for creating objects. It encapsulates data
(attributes) and methods (functions).
Example:
python
Copy code
class Person:
self.name = name
self.age = age
def greet(self):
person1.greet()
Output:
csharp
Copy code
python
Copy code
def factorial(n):
if n == 1: # Base case
return 1
else:
Answer:
The scope of a variable refers to the context in which the variable is
accessible:
Example:
python
Copy code
x = 10 # Global variable
def outer():
y = 20 # Enclosing variable
def inner():
nonlocal y
y += 10
print(y)
inner()
outer()
Answer:
Built-in functions in Python are predefined functions that can be used
without importing any module. Examples include:
Example:
python
Copy code
nums = [1, 2, 3, 4]
print(len(nums)) # Output: 4
print(sum(nums)) # Output: 10
Answer:
String slicing allows extracting a portion of a string by specifying a range
of indices. The syntax is:
string[start:end:step]
Example:
python
Copy code
Answer:
A Decision Table is a tabular representation of decision logic. It lists all
possible conditions and actions for a particular problem. It helps in
systematic decision-making by identifying all possible scenarios.
Structure Example:
Action Action
Conditions
1 2
Condition 1:
Yes No
True
Condition 2:
No Yes
False
Answer:
A list in Python is a mutable, ordered collection of elements. Lists can
store elements of different data types and allow duplicate values.
Example:
python
Copy code
Answer:
Characteristics of Python Programming:
Identifiers:
Rules:
Keywords:
Reserved words in Python with specific meanings (e.g., if, else, for,
while).
Answer:
python
Copy code
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
target = 30
if result != -1:
else:
Answer:
Relational Operators: Compare values and return a boolean.
Example:
python
Copy code
x, y = 5, 10
Example:
python
Copy code
x, y = True, False
Answer:
A Python program typically consists of:
Example:
python
Copy code
# Import
import math
# Global variable
PI = 3.14
# Function
def area_circle(radius):
return PI * radius ** 2
# Main execution
if __name__ == "__main__":
Answer:
Major programming methodologies include:
Answer:
python
Copy code
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
fibonacci(10) # Output: 0 1 1 2 3 5 8 13 21 34
python
Copy code
def insertion_sort(arr):
key = arr[i]
j=i-1
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
insertion_sort(numbers)
(b) Write a program to create Stack class and implement all its
methods.
Answer:
python
Copy code
class Stack:
def __init__(self):
self.items = []
self.items.append(item)
def pop(self):
if not self.is_empty():
return self.items.pop()
else:
def peek(self):
if not self.is_empty():
return self.items[-1]
else:
return "Stack is empty"
def is_empty(self):
return len(self.items) == 0
def size(self):
return len(self.items)
# Example Usage
stack = Stack()
stack.push(10)
stack.push(20)
print(stack.peek()) # Output: 20
print(stack.pop()) # Output: 20
print(stack.pop()) # Output: 10
Answer:
python
Copy code
def check_even_odd(number):
if number % 2 == 0:
return "Even"
else:
return "Odd"
# Example Usage
Answer:
python
Copy code
def reverse_number(number):
reversed_num = int(str(number)[::-1])
return reversed_num
# Example Usage
Code:
python
Copy code
stack = Stack()
stack.push(10)
stack.push(20)
print(stack.peek()) # Output: 20
print(stack.pop()) # Output: 20
print(stack.pop()) # Output: 10
Output:
csharp
Copy code
20
20
10
Stack is empty
Code:
python
Copy code
csharp
Copy code
python
Copy code
csharp
Copy code
Code:
python
Copy code
num = 12345 # Example Input
Output:
python
Copy code
python
Copy code
Output:
python
Copy code
THANK YOU