Python Programming Practice Assignment
[Link]. Questions
1 What is set comprehension in Python? Write an example to generate squares of numbers
from 1 to 5.
2 What is dictionary comprehension in Python? Explain with an example.
3 Predict the output of the code: a = [10, 20, 30]; b = [Link](); b[0] = 100; print(a),
print(b).
4 What will be the output of the code: x = [1, 2, 3]; y = x; [Link](4); print(x).
5 Write a Python program to demonstrate the difference between insert() and append().
6 Write a Python program to demonstrate the difference between remove() and pop()
methods in a list.
7 Explain the purpose of the zip() function in Python. Provide syntax and an example.
8 Explain the purpose of the enumerate() function in Python. Provide syntax and example.
9 What will be the output of the code with break and else in loop? Explain.
10 Predict the output of a for loop with range(3) and else block.
11 Write a Python program that accepts a string, checks if it is an anagram of its reverse,
counts frequency of characters, and displays results.
12 Write a Python program that accepts a string, counts uppercase and lowercase letters,
replaces digits with *, and prints modified string.
13 Explain positional vs keyword arguments in Python functions with examples.
14 What are keyword arguments in Python functions? Explain with an example.
15 What is a generator function in Python? How is it different from a normal function?
Write a generator for first n even numbers.
16 Explain map() function in Python. How is it different from list comprehension? Provide
examples.
17 Explain file handling in Python: difference between read(), readline(), readlines() with
examples.
18 Explain file handling modes (r, w, a, rb, etc.) with examples.
19 Write a Python program to read a file, count uppercase, lowercase, digits, and write
results to another file.
20 Write a Python program to read a file and count sentences, words, and characters.
21 Explain boolean indexing in NumPy. Example: select elements divisible by 3.
22 Explain filtering elements in NumPy based on conditions (e.g., divisible by 2).
23 Convert dictionary to pandas DataFrame and DataFrame to list of dictionaries with
examples.
24 Convert list to NumPy array and NumPy array to pandas DataFrame with examples.
25 Explain data discretization (equal-width and equal-frequency binning), compare them,
and demonstrate using pandas.
26 Explain equal-width vs equal-frequency binning with comparison and Python example.
27 Write a pandas program for [Link] to load data, display records, calculate revenue,
count completed orders, group by customer, and check nulls.
28 Write a pandas program for [Link] to load data, display rows, compute total column,
find lowest sales, show summary, and check duplicates.