Unit-wise Important Question Bank - Python Bcc402
Unit-wise Important Question Bank - Python Bcc402
PYTHON BCC402
UNIT 1
1. Differentiate between / and // operator with an example.
def count1(s):
vowels = "AEIOUaeiou"
count = 0
print("@".join(list1))
16. What is the significance of dynamic typing in Python? Write a Python program to
demonstrate dynamic typing using variable reassignment of different data types.
18. Write a Python program to convert a given character into its ASCII value and vice
versa.
19. Explain how 'else' clause can be used with 'for' loop in Python. Write a Python
program to check if a number is prime using 'for-else'.
20. Write a Python program to remove all falsy values (0, None, False, [], '', etc.) from a list
using the filter() function. Show the output for the list: [1, 0, 0, 2, 'hi', ' ', []].
21. Explain 'split()' and 'join()' string functions with proper examples. Write a Python
program that converts a comma-separated string to a list and vice versa.
22. Write a Python program to demonstrate mutable and immutable types by modifying
a list and showing the error when trying to modify a tuple.
23. Write a Python code to demonstrate variable scope in Python. Explain with an
example showing the difference between global and local variables.
24. Explain the concept of Python blocks (Indentation) with an example. What error does
Python throw if indentation is not proper? Write a program showing the error.
25. Write a Python program to check the type of various data types (int, float, complex,
str, bool) using the type() function and print their types dynamically.
4. Demonstrate five different built-in functions used in string operations. Write a program to check
whether a string is a palindrome.
5. Explain for and while loops with flow diagrams and examples.
10. Write a Python program using a for loop to print the multiplication table of a number entered
by the user.
11. Develop a Python program that prints all prime numbers between 1 and 100 using for and else
clauses.
12. Write a Python program that calculates the factorial of a number using both while loop and for
loop separately.
13. Write a Python program to check if the given string is a palindrome using while loop (without
slicing or reverse methods).
14. Explain how the pass statement works inside loops. Write a Python code where the pass
statement is used inside an empty if block within a for loop.
15. Write a Python program using nested for loops to print the following pattern:
2 2
3 3 3
4 4 4 4
17. Explain the difference between while and do-while loop constructs. Write a Python equivalent
to simulate a do-while loop to accept numbers until a positive number is entered.
18. Write a Python program to demonstrate the use of nested if-else for determining the largest of
three numbers.
19. Write a Python program to count the number of vowels and consonants in a given string using
a for loop and if-else conditions.
2. Show an example where both Keyword arguments and Default arguments are used
for the same function.
3. Write a Python program triangle(N) that prints a right triangle pattern using *.
11. Write a Python program to remove all duplicates from a list without using set(). Print
the original and the modified list.
12. Explain how to create a Dictionary in Python. Write a program to count the frequency
of each character in a given string using a dictionary.
13. Write a Python function that accepts a list of numbers and returns both the maximum
and minimum values (without using built-in functions like max() or min()).
14. What is list comprehension? Write a Python program to create a list of squares of even
numbers from 1 to 20 using list comprehension.
15. Explain the difference between mutable and immutable data types in Python with
suitable examples for each.
16. Write a Python program to merge two dictionaries into one. Demonstrate with an
example.
17. Develop a Python function to accept a tuple of numbers and return a new tuple
containing only the even numbers.
18. Explain the concept of a Python set. Write a program to perform union, intersection,
and difference operations on two sets.
20. Create a Python function that accepts any number of positional arguments and returns
their sum. Demonstrate by calling the function with 3, 5, 10, and 15 as arguments.
3. Find the largest word present in a file using Python file handling.
6. How to create a Python file that can be imported as a library as well as run as a
standalone script?
7. Describe the difference between import library and from library import * in Python.
10. Write a Python program to open a text file in write mode, write multiple lines of data
into it, and then read the contents of the file.
11. Explain the difference between the file modes 'r', 'w', 'a', and 'r+' with suitable
examples for each.
12. Write a Python program to count the total number of words, characters, and lines in a
file named data.txt.
13. Explain the seek() and tell() functions in Python file handling with proper examples.
14. Write a Python program that reads a file and prints each line after stripping the
newline (\n) character.
15. Explain how exception handling is used during file operations in Python. Write a
program that handles the error when a file does not exist.
16. Write a Python program to copy contents of one file into another file.
17. What is the significance of using the with statement for file handling in Python?
Explain with an example where a file is read using this method.
18. Write a Python program to read a CSV file and display its contents line by line.
3. Write a Python GUI program to create a label and change its font style using Tkinter.
6. Explain the difference between a NumPy array and a Python list with suitable examples.
8. Describe the reshape() function in NumPy. Write a Python code to convert a 1D array
to a 2D array using reshape().
10. Explain the concept of DataFrame in Pandas. Write a Python program to create a
DataFrame from a dictionary and display it.
11. Write a Python program to read a CSV file into a Pandas DataFrame and display the
first 5 rows using head().
13. Write a Python program to filter rows in a Pandas DataFrame where a column value is
greater than a specified number.
15. Write a Python program to plot a bar chart using Matplotlib with sample data.
16. Explain the role of labels, title, and legend in a Matplotlib plot with an example plot.
17. Write a Python program to plot a pie chart using Matplotlib showing the percentage
distribution of marks in five subjects.
18. Write a Python GUI application using Tkinter to create a simple calculator that
performs addition and subtraction.
19. List and explain any five commonly used Tkinter widgets with examples of their usage.