0% found this document useful (0 votes)
32 views5 pages

QB Python 2024-25

The document is a question bank for an Introduction to Python Programming course for the academic year 2024-25. It covers various modules including Python basics, data structures, string manipulation, file handling, debugging, and object-oriented programming, with specific questions and programming tasks for each topic. Each module contains theoretical questions, programming exercises, and explanations of concepts related to Python programming.

Uploaded by

gsjayanth373
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views5 pages

QB Python 2024-25

The document is a question bank for an Introduction to Python Programming course for the academic year 2024-25. It covers various modules including Python basics, data structures, string manipulation, file handling, debugging, and object-oriented programming, with specific questions and programming tasks for each topic. Each module contains theoretical questions, programming exercises, and explanations of concepts related to Python programming.

Uploaded by

gsjayanth373
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Question Bank Introduction to Python Programming (BPLCK105B) AY 2024-25

Module-1: Python Basics, Flow Control and Functions


1. Explain the rules for creating variables with examples.
2. Find the output:
a,b,c=7,14,21
print(a+c%10*b-a**2+b//a/2)
3. Evaluate the output of below program.
a='nie'
print(a*2)
print('nie'+'nienie')
print(a+a)
print(a+'nie'+a)
print('nie'+a*2)
print('nie'+a*2+a)
4. Write a program to find the area and perimeter of circle.
5. Write a program to check whether a number is positive or negative.
6. Write a program to check whether number is odd or even.
7. Write a program to find the maximum of two numbers entered by user.
8. Write a program to find the maximum of three numbers entered by user.
9. Write a program to check whether a person is senior citizen or not.
10. List the different loop control statements available in python. Explain with suitable
examples.
11. Write a program to print even integers between 1 and 20 using while loop.
12. Write a program to print odd integers between n1 and n2 using for loop where n1 and n2
are positive inputs entered by the user and n2>n1.
13. Write a program to print odd integers between 1 and N using for loop.
14. Write a program to print odd integers between n1 and n2 using while loop where n1 and
n2 are positive inputs entered by the user and n2>n1.
15. Write a program to find the factorial of an integer entered by the user.
16. Write a program to find the binomial coefficient nCr, where n and r are user inputs.
17. Write a program to generate first N Fibonacci numbers, where N is the user input.
18. Evaluate the output of below program.
for i in range(2,11):
if i%3==0:
continue
elif i%7==0:
break
else:
print(i)
19. Write a program to find the sum of all the digits of a given integer number.
20. Write a program to reverse an integer number and check whether it is palindrome or not.
21. Write a program to find the sum of integers between 1 to N, where N is positive user
input. (hint: 1 + 2 + 3 + . . . . . . + N)
22. Write a program to evaluate the following expression, where n is the uses input.
1 2 + 22 + 32 + . . . . . . . + n 2
23. Write a program to compute sum of odd numbers, even numbers and all numbers between
1 and N, where N is positive user input, using for statement.
24. Write a program to compute sum of odd numbers, even numbers and all numbers between
1 and N, where N is positive user input, using while statement.
25. Explain different categories of functions with respect to arguments and return value.
26. Write a function to find a factorial of a given number.
Dr. Harshavardhan B., Asst. Prof., Mech. Engg. Dept., NIE , Mysuru 1
Question Bank Introduction to Python Programming (BPLCK105B) AY 2024-25

27. Write a function to find the binomial coefficient of nCr, where n and r are user inputs.
28. Write functions to find the area and perimeter of a rectangle.
29. Write a program to find the area and perimeter of a circle using functions.
30. Write a function to find the maximum of three numbers.
31. Explain error handling with try-except blocks using suitable examples.
32. Write a program to illustrate the handling of TypeError and SyntaxError using try-except
blocks.

Module-2: Lists, Dictionaries and Structuring Data


1. How do you create a list in python? Illustrate the use of negative indexing of list with
examples.
2. Explain the following methods used in lists with their syntax. i) append ii) extend iii)
insert iv) pop v) remove vi) clear vii) index viii) count ix) sort x) reverse
3. Write a program to read N integers into a list and find the minimum, maximum, sum,
mean and standard deviation of items in the list.
4. Write a program to generate the first N Fibonacci numbers using list.
5. Write a function find_even that takes a list of integers as argument and returns a new list
containing only even numbers.
6. Create a list with following items: 3, „hi‟, 5.0, None, True, 6, 8, 10 and store it in a
variable „spam‟ and write the code to perform the following:
i) Print the index of item None
ii) Insert the item „Python‟ at the position 3 and print the list
iii) Add the item -4 at the end of the list and print the list
iv) Remove the item „hi‟ and print the list
v) Slice the list of first 5 items from the updated list of spam
7. Explain the use of following methods used in dictionary with their syntax. i) keys() ii)
values() iii) items() iv) update() v)popitem() vi) pop()
8. Write a program to read a multi-digit number as string from the console and find the
occurrence of each digit using a dictionary.
9. Write a program to display a dictionary with its keys as numbers from 1 to 5 (both
included) and values as cube of the keys i.e. {1:1, 2:8, 3:27, 4:64, 5:125}
10. Write a program to sort the dictionary based on keys.
11. Write a program to sort the dictionary based on values.
12. For a given dictionary d={„bus‟:3, „truck‟:8, „car‟:6, „bike‟:5}, write a program to print
the dictionary with values more than 5.
13. Given a dictionary structure in python:
data={„name‟: „John‟, „age‟: 30, „city‟: „New York‟, „skills‟:[„Python‟, „Java‟, „SQL‟]}
Explain the pprint.pformat() function and also predict the output when data is printed
using this method.
14. Evaluate the output of below program.
L=['cat','sat','on','mat']
Lnew=[]
for i in L:
if 'a' not in i:
Lnew.append(i)
print(Lnew)
15. my_tuple=(1, 2, 3, 4, 5)
try:
my_tuple[0]=10 # this line should raise an error
except TypeError as e:
print(f „TypeError {e}‟)
Explain the precise error that is thrown in the code above and demonstrate how this
showcases the immutability of tuples in python.
Dr. Harshavardhan B., Asst. Prof., Mech. Engg. Dept., NIE , Mysuru 2
Question Bank Introduction to Python Programming (BPLCK105B) AY 2024-25

16. Differentiate between a dictionary, list and tuple with appropriate examples.

Module-3: Manipulating Strings, Reading and Writing Files


1. Given the string example_str= “Hello, World!”
Use the built-in methods to:
i) Check if the string starts with “Hello”
ii) Check if the string ends with an exclamation mark (!)
iii) Right-Justify the string with a total width of 20 characters
iv) Split the string into a list of words
v) Remove any trailing whitespaces form the sting
2. Given the string example_str= “Hello, World!”
Evaluate the following expressions:
i) example_str[3:]
ii) example_str.upper().lower()
iii) example_str.split()
iv) „Hello‟ in example_str
v) example_str.istitle()
3. Write the output of the python program given below.
a= „Introduction to Python Programming‟
b= „ Hello, World ‟
print(a.istitle())
print(a.split())
print(a.ljust(38, „*‟))
print(b.rstrip())
print(„_‟.join(a.split()))
4. Evaluate the following python expressions and analyze the results.
i) „Hello world!‟[3:]
ii) „Hello‟.upper().lower()
iii) „Remember, remember, the fifth of November.‟.split()
iv) „HELLO‟ in „Hello World‟
v) „This Is Title Case 123‟.istitle()
5. Write a program to count the total number of vowels, consonants and blanks in a string.
6. Explain the use of join(), split() and strip() methods with examples.
7. Explain the following string functions: i) isalpha() ii)isalnum() iii) title() iv) capitalize()
8. Perform the following string operations in python with an example for each.
a. Concatenate three different strings
b. Check whether the given string is palindrome or not
c. Find the length of the string
d. Convert the given string to upper case
e. Covert the given string to a list
9. Write a program to read a string and check whether the string is alphabet, alphanumerical,
decimal, space or title case using if statement.
10. Write a program that takes a string as input from the user and counts the number of
alphabets, digits and special characters in it.
11. Write a program to check if a given string exists inside a list of strings. Further, if the
given string exists, print the number of its occurrences in the list.
12. With a suitable program, explain the process of creating a text file, writing and reading
contents to/from the file. (or) Explain the file handling in python with suitable examples
for both reading and writing a text file.
13. Develop a program to sort the contents of a text file and write the sorted contents into a
separate text file.(Lab program)

Dr. Harshavardhan B., Asst. Prof., Mech. Engg. Dept., NIE , Mysuru 3
Question Bank Introduction to Python Programming (BPLCK105B) AY 2024-25

14. Write a program that reads the contents of a text file named „data.txt‟ and prints the first
line to the console if the line ends with characters „nie‟. Use proper file handling
techniques and include comments in your code.
15. Explain the following with its syntax:
a. Get to know the current working directory
b. Creates a new directory at the specified path
c. Change the current working directory
d. Remove a directory
e. List all the files and sub directories present inside the current working directory
f. Renaming a file or directory
16. Describe the following methods of os module: i) chdir() ii) rmdir() iii) walk() iv) mkdir()
v) getcwd()
17. Write a program to create a file using shelve module and append the variables to it and
read it.

Module-4: Organizing Files, Debugging


1. Write a program to walk through all the files and subfolders of a given directory/current
working directory.
2. Explain the following code:
import os
for f1,f2,f3 in os.walk(os.getcwd()):
print(f1)
print(f2)
print(f3)
3. Write a program that demonstrates how to compress and decompress a folder using the
zipfile module (or) write a program to create a new zip file and add multiple files to zip
file.
4. Write a code to create a zip file called „new_zip_file.zip‟ using zipfile module. Add the
files „file1.txt‟ and „file2.txt‟ to „new_zip_file.zip‟. Further, show how to extract all the
files using zipfile module.
5. Explain the following with its syntax:
a. Copy a file from the source to the destination
b. Copy an entire folder and all its contents to the destination folder
c. Remove a directory and all its contents recursively
d. Move a file or directory form the source to the destination
6. Write a program to copy, move and delete the contents of file through „shutil module‟.
7. Explain error handling with raise and assert keywords with a suitable program.
8. Write a function named DivExp which takes two parameters a,b and returns value c
(c=a/b). Write suitable assertion for a>0 in function DivExp and raise an exception for
when b=0. Develop a suitable program which reads two values from the console and calls
a function DivExp. (Lab program)
9. Write a program to read a positive number from the user and check whether the entered
number is an even number. If the entered number is negative, print error message as
„Error! Number is negative‟ using assert.
10. List and explain five different levels of logging in python with a suitable program.

Module-5: Classes, objects, functions, methods


1. Explain class and objects with a suitable program.
2. Discuss the pure functions and modifiers for a class in python.
3. Explain copying of the objects with a suitable program.
4. Write a class rectangle and create methods area() and perimeter() to find the area and
perimeter of a rectangle for given input length and breadth by user
Dr. Harshavardhan B., Asst. Prof., Mech. Engg. Dept., NIE , Mysuru 4
Question Bank Introduction to Python Programming (BPLCK105B) AY 2024-25

5. Write a Rectangle class and create two Rectangle objects. Write python program to check
whether the area of the first Rectangle object is greater than second Rectangle object.
(with or without operator over loading).
6. Write a class circle and create methods area() and perimeter() to find the area and
perimeter of a circle for given input radius by user.
7. Develop a program that uses class Student which prompts the user to enter marks in three
subjects and calculates total marks, percentage and displays the score card details. Use list
to store the marks in three subjects and total marks. Use __init__() method to initialize
name, USN and the lists to store marks and total. Use getMarks() method to read marks
into the list, and display() method to display the score card details. (Lab program)
---***---

Dr. Harshavardhan B., Asst. Prof., Mech. Engg. Dept., NIE , Mysuru 5

You might also like