Tuesday, April 29, 2025

BCA PAPER CODE BCAC301 SEM -3 [2025]

 

MAULANA ABUL KALAM AZAD UNIVERSITY OF TECHNOLOGY, WEST BENGAL

Paper Code: BCAC301
Python Programming
UPID: 3000070

Time Allotted: 3 Hours
Full Marks: 70

The figures in the margin indicate full marks.
Candidates are required to give their answers in their own words as far as practicable.


Group-A (Very Short Answer Type Questions)

Answer any ten of the following: (1 × 10 = 10)

  1. Which command creates a list?

    • a) list1 = list()

    • b) list1 = []

    • c) list1 = list([1, 2, 3])

    • d) All of the mentioned ✓

  2. Python tuple example:

    • Correct answer: None of the options (tuples use ( ), e.g., (1, 2, 3)).

  3. False statement about dictionaries:

    • b) "The keys of a dictionary can be accessed using values" (False).

  4. Open file for writing:

    • outfile = open("c:\\scores.txt", "w") (escape backslash or use raw string).

  5. Python creator:

    • c) Guido van Rossum ✓

  6. Python keywords:

    • b) lower case (e.g., ifdef).

  7. Single-line comment symbol:

    • # (None of the options match; typo in the question).

  8. String slicing output (str1[::-1]):

    • a) "dlrowolleh" (reversed string).

  9. Function definition keyword:

    • c) def ✓

  10. Shuffle a list:

    • c) random.shuffle(fruit) (requires import random).

  11. Set slicing output (t[1:-1]):

    • Error (sets are unordered; slicing not supported).

  12. Arithmetic operators with strings:

    • c) - (cannot be used).


Group-B (Short Answer Type Questions)

Answer any three of the following: (5 × 3 = 15)

2. Read/Write Text File in Python

  • Reading:

    python
    Copy
    Download
    with open("file.txt", "r") as file:
        content = file.read()
  • Writing:

    python
    Copy
    Download
    with open("file.txt", "w") as file:
        file.write("Hello, World!")

3. Dictionary Example

python
Copy
Download
student = {"name": "Alice", "age": 21, "grade": "A"}  
print(student["name"])  # Output: Alice

4. Identifier Token

  • Rules:

    • Start with [a-zA-Z_], followed by [a-zA-Z0-9_].

    • Case-sensitive (var ≠ Var).

    • Cannot use keywords (e.g., ifwhile).

5. OOP Features

  1. Encapsulation (e.g., classes).

  2. Inheritance (e.g., class Child(Parent)).

  3. Polymorphism (e.g., method overriding).

  4. Abstraction (e.g., abstract classes).

6. for vs. while Loops

  • for: Iterates over sequences.

    python
    Copy
    Download
    for i in range(5): print(i)  # 0,1,2,3,4
  • while: Runs until condition is False.

    python
    Copy
    Download
    i = 0
    while i < 5: print(i); i += 1  # 0,1,2,3,4

Group-C (Long Answer Type Questions)

Answer any three of the following: (15 × 3 = 45)

7. String Operations

(a) Slicing:

python
Copy
Download
text = "Python"
print(text[1:4])  # "yth"

(b) String Methods:

  • upper()split()replace()strip().
    (c) Strings in Python:

  • Immutable, support indexing/slicing, versatile methods.

8. Functions

(a) Definition:

python
Copy
Download
def greet(name):
    print(f"Hello, {name}!")

(b) Multiplication Table:

python
Copy
Download
def table(n):
    for i in range(1, 11): print(f"{n} x {i} = {n*i}")

(c) Fruitful Functions:

  • Return values (e.g., def add(a, b): return a + b).

9. Lists vs. Tuples

(a) Differences:

  • Lists: Mutable, [ ].

  • Tuples: Immutable, ( ).
    (b) append() vs. extend():

  • append(): Adds single element.

  • extend(): Adds multiple elements.
    (c) List Methods:

  • sort()reverse()pop()insert().

10. Tuples

(a) Definition:

python
Copy
Download
coordinates = (10, 20)

(b) Tuple Assignment:

python
Copy
Download
x, y = (10, 20)  # x=10, y=20

(c) Immutability:

  • Ensures data integrity (cannot modify after creation).

11. Python Features & Comparisons

(a) Python Features:

  • Easy syntax, dynamic typing, cross-platform.
    (b) Python vs. C:

  • Python: Interpreted, no pointers.

  • C: Compiled, manual memory management.
    (c) Python vs. Java Data Types:

  • Python: Dynamic (e.g., list).

  • Java: Static (e.g., ArrayList<String>).

*************************End of PAPER********************************************
SOLUTIONS
*****************************************************************************

Group-A (Very Short Answer Type Questions)

Solutions (Any 10):

  1. List Creation:

    • Correct Option: d) All of the mentioned (list()[], and list([1, 2, 3]) are valid).

  2. Python Tuple:

    • Correction: The options are incorrect (tuples use parentheses, e.g., (1, 2, 3)).

  3. False Dictionary Statement:

    • Answer: b) "The keys of a dictionary can be accessed using values" (False; keys are unique and used to access values).

  4. File Opening:

    • Answer: outfile = open("c:\\scores.txt", "w") (escape backslashes or use raw string: r"c:\scores.txt").

  5. Python Creator:

    • Answer: c) Guido van Rossum.

  6. Keywords Case:

    • Answer: b) lower case (e.g., ifdef).

  7. Single-line Comment:

    • Correction: Python uses # (options are incorrect).

  8. String Slicing (str1[::-1]):

    • Answer: Reverses the string → "dlrowolleh".

  9. Function Definition:

    • Answer: c) def.

  10. List Shuffling:

    • Answer: c) random.shuffle(fruit) (requires import random).

  11. Set Slicing:

    • Answer: Error (sets are unordered; slicing not supported).

  12. String Arithmetic:

    • Answer: c) - (cannot be used with strings).


Group-B (Short Answer Type Questions)

2. Reading/Writing Text Files

Solution:

python
Copy
Download
# Writing to a file
with open("example.txt", "w") as file:
    file.write("Hello, Python!")

# Reading from a file
with open("example.txt", "r") as file:
    content = file.read()
    print(content)  # Output: Hello, Python!

3. Dictionary Example

Solution:

python
Copy
Download
student = {"name": "Alice", "age": 21, "grade": "A"}
print(student["name"])  # Output: Alice

4. Identifier Token Rules

Key Points:

  • Must start with [a-zA-Z_].

  • Can include [a-zA-Z0-9_] thereafter.

  • Case-sensitive (myVar ≠ myvar).

  • Cannot use keywords (e.g., forwhile).

5. OOP Features

Solution:

  1. Encapsulation: Bundling data/methods (e.g., classes).

  2. Inheritance: class Child(Parent):.

  3. Polymorphism: Method overriding (len() works for strings/lists).

  4. Abstraction: Hiding complexity (e.g., abstract classes).

6. for vs. while Loops

Solution:

  • for: Iterates over sequences (lists, strings).

    python
    Copy
    Download
    for i in range(3): print(i)  # 0, 1, 2
  • while: Runs until condition is False.

    python
    Copy
    Download
    i = 0
    while i < 3: print(i); i += 1  # 0, 1, 2

Group-C (Long Answer Type Questions)

7. String Operations

(a) Slicing:

python
Copy
Download
text = "Python"
print(text[1:4])  # "yth"

(b) String Methods:

  • upper() → Converts to uppercase.

  • split() → Splits into a list.

  • replace("old", "new") → Replaces substrings.

  • strip() → Removes whitespace.

(c) String Properties:

  • Immutable (cannot modify after creation).

  • Support indexing (text[0]) and slicing (text[1:3]).

8. Functions

(a) Definition:

python
Copy
Download
def greet(name):
    print(f"Hello, {name}!")

(b) Multiplication Table:

python
Copy
Download
def print_table(n):
    for i in range(1, 11):
        print(f"{n} x {i} = {n*i}")

(c) Fruitful Functions:

  • Return values (e.g., return a + b).

  • Example:

    python
    Copy
    Download
    def add(a, b):
        return a + b
    result = add(3, 5)  # 8

9. Lists vs. Tuples

(a) Differences:

Lists ([])Tuples (())
MutableImmutable
Slower iterationFaster iteration
More memoryLess memory

(b) append() vs. extend():

  • append(): Adds a single element.

    python
    Copy
    Download
    lst = [1, 2]; lst.append(3)  # [1, 2, 3]
  • extend(): Adds multiple elements.

    python
    Copy
    Download
    lst.extend([4, 5])  # [1, 2, 3, 4, 5]

(c) List Methods:

  • sort(): Sorts in-place.

  • reverse(): Reverses the list.

  • pop(): Removes by index.

10. Tuples

(a) Definition:

python
Copy
Download
coordinates = (10, 20)

(b) Tuple Assignment:

python
Copy
Download
x, y = (10, 20)  # x=10, y=20

(c) Immutability:

  • Ensures data integrity (e.g., for dictionary keys).

11. Python Features & Comparisons

(a) Python Features:

  • Dynamic typing, easy syntax, cross-platform.
    (b) Python vs. C:

  • Python: Interpreted, no manual memory management.

  • C: Compiled, supports pointers.
    (c) Python vs. Java Data Types:

  • Python: list (dynamic), int (unbounded).

  • Java: ArrayList<String> (static), int (32-bit).



Thanks
SK Institute



No comments:

Post a Comment