Python Programming - B.Tech 2nd Semester Examination, 2025

2025Semester 3Civil-CAEnd Semester
Bihar Engineering University, Patna
B.Tech 2nd Semester Examination, 2025

Python Programming

Time: 03 HoursCode: 100218Full Marks: 70

Instructions:

  1. The marks are indicated in the right-hand margin.
  2. There are NINE questions in this paper.
  3. Attempt FIVE questions in all.
  4. Question No. 1 is compulsory.
Q.1 Choose the correct option / answer the following (Any seven question only):[14]
  1. Which of the following is a valid variable name in Python?

    1. 2value
    2. value2
    3. value-2
    4. value 2
  2. Which symbol is used for comments in Python?

    1. //
    2. /* */
    3. #
    4. <!-- -->
  3. Which function is used to take input from the user?

    1. scanf()
    2. gets()
    3. read()
    4. input()
  4. Which of the following will create an empty dictionary?

    1. dict()
    2. {}
    3. []
    4. set()
  5. What is the correct syntax to define a function in Python?

    1. function fun():
    2. def fun():
    3. def fun[]:
    4. define fun():
  6. "Hello"[1] gives:

    1. H
    2. e
    3. l
    4. o
  7. Which method is used to find length of a string?

    1. length()
    2. size()
    3. count()
    4. len()
  8. Lists in Python are

    1. Mutable
    2. Immutable
    3. Constant
    4. None
  9. Which method removes the last element from a list?

    1. remove()
    2. pop()
    3. clear()
    4. delete()
  10. Which of the following is used to open a file in Python?

    1. file()
    2. open()
    3. read()
    4. fopen()
Q.2 Solve both questions:[14]
  1. Explain Identifiers, Keywords, Statements, and Expressions in Python.

  2. Explore the working of while and for loop with examples.

Q.3 Solve both questions:[14]
  1. Explain Assignment and Relational operators in python with program?

  2. What is type conversion? Explain with example?

Q.4 Solve both questions:[14]
  1. Explain elseif ladder in python programming with suitable example.

  2. Write a Python program to count how many numbers in a given list are even and how many are odd.

Q.5 Solve both questions:[14]
  1. Explain the scope and lifetime of variables with examples. Also demonstrate how the global keyword is used to modify global variables inside a function.

  2. Write a function factors (N) that returns a list of all positive divisors of N (N>=1).
    For example:
    factors (6) returns [1,2,3,6]
    factors (1) returns [1]
    factors (13) returns [1,13]

Q.6 Solve both questions:[14]
  1. Explain concatenation, comparison, and length operation. Support your explanation with suitable example programs.

  2. Explain commonly used string methods such as upper(), lower(), strip(), find(), replace(), split(), join(), etc. Write example code demonstrating at least five string methods.

Q.7 Solve both questions:[14]
  1. Explain operations such as concatenation, repetition, membership, and length in list with program?

  2. Explain indexing and slicing in lists with examples. Discuss: Positive and negative indexing, Accessing single elements, Slicing formats: list[start:end], list[start:end:step].

Q.8 Solve both questions:[14]
  1. What are nested loops? Write a program to print the following pattern using nested for loops:

    *
    * *
    * * *
    * * * *

  2. Explain commonly used methods like add(), update(), remove(), discard(), union() in set with program?

Q.9 Solve both questions:[14]
  1. How to perform read operation in text file explain with example?

  2. Write a Python function to count the frequency of each character in a given a string and return the output in a dictionary. Example: char_frequency ("HELLO") returns {'H': 1, 'E': 1, 'L': 2, 'O': 1}.