Python Programming - B.Tech 2nd Semester Examination, 2025
Python Programming
Instructions:
- The marks are indicated in the right-hand margin.
- There are NINE questions in this paper.
- Attempt FIVE questions in all.
- Question No. 1 is compulsory.
-
Which of the following is a valid variable name in Python?
-
Which symbol is used for comments in Python?
-
Which function is used to take input from the user?
-
Which of the following will create an empty dictionary?
-
What is the correct syntax to define a function in Python?
-
"Hello"[1] gives:
-
Which method is used to find length of a string?
-
Lists in Python are
-
Which method removes the last element from a list?
-
Which of the following is used to open a file in Python?
-
Explain Identifiers, Keywords, Statements, and Expressions in Python.
-
Explore the working of while and for loop with examples.
-
Explain Assignment and Relational operators in python with program?
-
What is type conversion? Explain with example?
-
Explain elseif ladder in python programming with suitable example.
-
Write a Python program to count how many numbers in a given list are even and how many are odd.
-
Explain the scope and lifetime of variables with examples. Also demonstrate how the global keyword is used to modify global variables inside a function.
-
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]
-
Explain concatenation, comparison, and length operation. Support your explanation with suitable example programs.
-
Explain commonly used string methods such as upper(), lower(), strip(), find(), replace(), split(), join(), etc. Write example code demonstrating at least five string methods.
-
Explain operations such as concatenation, repetition, membership, and length in list with program?
-
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].
-
What are nested loops? Write a program to print the following pattern using nested for loops:
*
* *
* * *
* * * *
-
Explain commonly used methods like add(), update(), remove(), discard(), union() in set with program?
-
How to perform read operation in text file explain with example?
-
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}.