0% found this document useful (0 votes)
3 views9 pages

QB Python

The document contains a series of programming questions and tasks related to Python, organized into five units. Topics covered include operator precedence, data structures, object-oriented programming, exception handling, file operations, and GUI design. Each unit presents various programming challenges, such as implementing classes, handling user input, and performing database operations.

Uploaded by

sarthakborekar77
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)
3 views9 pages

QB Python

The document contains a series of programming questions and tasks related to Python, organized into five units. Topics covered include operator precedence, data structures, object-oriented programming, exception handling, file operations, and GUI design. Each unit presents various programming challenges, such as implementing classes, handling user input, and performing database operations.

Uploaded by

sarthakborekar77
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

UNIT-I

Q.1 Argue the order of precedence of operators from highest to lowest and also write a program
for operator’s precedence including all the operators. Compute the following expression.(20 - 2
** 5 // 3*2 + 5>>2)

Q.2 Explain different types of operators that can help programmer to work in python
environment. Use short python code to explain your answer.

Q.3 Change the given table logic into a python script that decides activity of a weather, and print
the appropriate message for Activity, depending on the value of the Rules (1 and 2)given.

Temperature Humidity[Rule 2] Activity


[Rule 1]
Warm Dry Play Basketball
Warm Humid Play Tennis
Cold Dry Play Cricket
Cold Humid Swim

Q.4 Explain string object in python and operation on string with suitable code. For any type of
objects in python programming '!=' Is Not 'is not', Justify your answer using diagram or small
code.

Q.5 Write a program to read a four digit number through the keyboard and calculate the sum of
its digits.

Q.6 Discuss the 10 key features of Python.

Q.7 Given two sets, check whether set-1 is subset of set-2. Also, if set-1 is not subset of set-2
remove the common elements from set-1 to make both sets disjoint. Present all test cases and
solutions.

Q.8 Write a program to add 10 consecutive numbers starting from 1.

Q.9 Write a program to print the reverse of the entered number.

Q.10 Write a program to print the sum of digits of a given number.

Q.11 WAP to add the numbers in range that are divisible by 2. OR sum of even numbers in
range.

Q.12 Write a program to find whether the entered number is Armstrong , prime etc.

UNIT-II
Q.1 Illustrate the role of recursion to solve any complex problem. Construct a recursive function
to validate an additive sequence having following properties.
1. A valid string should contain at least three digit to make one additive sequence.
2. First and second number can’t start with 0.
3. Number of digits in added value can’t be smaller than digits.
Sample case:
s = “235813” True 2 + 3 = 5, 3 + 5 = 8, 5 + 8 = 13
s = “199100199” True 1 + 99 = 100, 99 + 100 = 199
s = “12345678” False 1+2=3, 2+3=5

Q.2 Write a program that prompts a user to enter the element of a list and add the element to a
list. Write a function maximum(Lst), minimum(Lst) and sortL(Lst) to find the maximum,
minimum number from the list and sorted order of the list.

Q.3 List the built-in function used in python programming. Identify major impact of different
types of argument in functions. Write a python program to convert a hexadecimal number
entered as a string into equivalent binary format.

Note: Use built-in function to obtain ASCII value of a character.

Sample Input:

Please Enter Hexadecimal Number:2FD

Sample Output:

Equivalent Binary Number is: 0001 0010 1111 1101

Q.4 Write a function calculate_grade(marks) that accepts marks in five subjects and calculates
the total, percentage, and corresponding grade based on the following:

Grade A: 90% and above

Grade B: 80-89%

Grade C: 70-79%

Grade D: 60-69%

Grade F: Below 60%

Q.5 Discuss the following dictionary methods with python code.


a) get()
b) keys()
c) pop()
d) update()
e) values()
f) items()

Q.6 Write the output of the following Python code:

def categorize_numbers(numbers):

result = {"even": [], "odd": []}

for num in numbers:

if num % 2 == 0:

result["even"].append(num)

else:

result["odd"].append(num)

return result

def filter_numbers(numbers, threshold):

return [num for num in numbers if num > threshold]

try:

input_list = [2, 5, 8, 1, 9, 6]

threshold = 4

categorized = categorize_numbers(input_list)

filtered_even = filter_numbers(categorized["even"], threshold)

filtered_odd = filter_numbers(categorized["odd"], threshold)

print(f"Filtered Even Numbers: {filtered_even}")


print(f"Filtered Odd Numbers: {filtered_odd}")

except Exception as e:

print(f"An error occurred: {e}")

Q.7 Write a program to repeatedly check for the largest number until the user enters “done”.

Q.8 Explain the use of local, non-local and global variable in Python using a program.

Q.9 Define Lists, Sets, Tuples and Dictionaries in python.

Q.10 Also compare these on following aspects:

i. Syntax for creation

ii. Mutability

iii. Sorting

UNIT-III

Q.1 Write a program to implement the concept of multiple inheritance.

a) Create the parent class Shape. Initialise the constructor with Shape.
b) Create another class named Rectangle which inherits the properties of the parent class
Shape. Define the attributes length and breadth in the Rectangle class. Initialise the
length and breadth inside the constructor of the Rectangle class. Also call the constructor
of the parent class to initialise the color of the Rectangle. Define the method calc_area()
to return the area of the rectangle.
c) Create another class named Triangle which inherits the properties of the parent
classShape. Define the attributes base and height in the Triangle class. Initialise the
baseand height inside the constructor of the Triangleclass. Also call the constructor of
theparent class to initialise the color of the Triangle. Define the method calc_area()
toreturn the area of the Triangle.
d) Also create the method Tring_Details() in the Triangle class and Rect_Details() inthe
Rectangle Class to return complete details about the rectangle and triangle.
Finally, create the instance of the Rectangle and Triangle classes to return the area ofthe
Rectangle and Triangle.

Q.2 Write a program to perform the following operation on complex numbers a+ib.

a) Addition b) Subtraction c) Multiplication d) Check if two complex number is equal


or not

Check if C1 ≥ C2

Check if C1 ≤ C2
Q.3 Write a program to implement the concept of single inheritance.

Create the parent class Circle. Initialise the constructor with the radius of the circle.

Define the method get_radius() and calc_area() to know the radius and area of the circle.

Create the child class named Cylinder. Initialise the value of the height within the
constructor and the constructor of the parent class to initialise the radius of the cylinder.

Finally define the method Calc_area() I the class Cylinderto calculate the area of the
cylinder.

Identify the use of abstract base classes in python programming using suitable code example.

Q.4 Explain the following principles of object-oriented programming (OOP) and demonstrate
how they are implemented in Python:

Encapsulation

Inheritance

Polymorphism

Q.5 Consider classes, A, B, C and D, whereas D is derived from A, B and C. Demonstrate


calling methods from A, B and C using object of D. Also, demonstrate the concept of overriding
in Python using example.

Q.6 Write the output of following expressions if

x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].

i.x[0:6:2]

ii. x[::-1]

iii. x[1] = 5

iv. after executing iii. If we execute 1 in x.

Q.7 Mention important concept of object-oriented approach that facilitates problems solving
easy, compared to procedure-oriented approach. Compare both methods respected to python
programming language.
Q.8 Write a Python function maxaverage(l) that takes a list of pairs of the form (name,score) as
argument, where name is a string and score is an integer. Each pair is to be interpreted as the
score of the named player.

For instance, an input of the form

[(‘Kohli’,73),(‘Rohit’,33),(‘Kohli’,7),(‘Hardik’,122),(‘Rohit,90)] represents two scores of 73


and 7 for Kohli, two scores of 33 and 90 for Rohit and one score of 122 for Hardik. Your
function should compute the players who have the highest average score (average = total across
all scores for that player divided by number of entries) and return the list of names of these
players as a list, sorted in alphabetical order. If there is a single player, the list will contain a
single name.

Q.9 Write a program to create class name Demo. Define two method Get_String() and
Print_String(). Accept the string from user and print the string in upper case.

Q.10 Describe types of inherence with examples.

UNIT-IV

Q.1 Illustrate the importance of exception handling in python programming. Write a python
program to handle wrong number of arguments for a method (say sqrt (), or pow ()). Use
suitable exception handling method to catch respective exception.

Q.2 Write a program to create a text file “[Link]” containing your name, DOB(dd/mm/yyy
format) and name of school, and to close it. If the file already exists, it should not create a file.
Write a script to reopen it and change the format from 'dd/mm/yyyy' to 'dd-mm-yyyy.’

Q.3 Write a program to read a text file [[Link]] from a relative path and count the frequency
of words appears in text file (having text paragraph), for each word (without escape characters /
delimiter). Write counted words and their frequency in file [[Link]].

Note: Updating [Link] must change on [Link]. sample work image given below.

Q.4 Write python scripts for database programming to perform the following operations:

i) create a table “[Link]” with ‘std_id’ as the primary key


ii) insert the data as given in the table below

Table: [Link]

std_id Course_id Semester Year Instructor

5 CSE2003 Fall 02 david

12 CSE3011 Fall 03 Ashwin

23 CSE2004 Spring 04 Bosch

98 MATH2110 Spring 03 Yang

102 CSE1310 Winter 04 david

iii) display the data

iv) update the data ‘david’ to ‘David’

v) insert the data entered through keyboard

Q.5 Explain the working of Generic Database Connectivity using ODBC with suitable
architecture.

Q.6 Rahul is an application developer in a company where server “X” is dedicated to handle
database requests/ response. Rahul is going to start working on an application development
where MySql database instancewill be usednamed “appDB”. What python code Rahul, need to
write for testing “appSchema” table connection using default MySql password for printing
CONNECTED / NOT [Link] the reason to prefer to MySql connection a
comparative to theMySqlLite / Postgre.

Q.7 Write a Python program to find the maximum number from resultant matrix after adding two
matrices of 3x3.

Q.8 Write a program to implement following function in any [Link] file

a) read
b) write
c) append
d) delete
e) open
f) insert
Q. 9 Write a Python program to get the file size of a plain file.
Q.10 Write a Python program to count the frequency of words in a file.
UNIT-V
Q.1 Create a basic HTML form that interacts with a Python CGI script? Illustrate mention steps
for building and testing CGI configuration. (Choose any web server such as Apache for
explaining your answer)

Q.2 Examine the cause for which Event driven paradigm is so popular. Construct a python script
for following GUI design (Use suitable widgets and respective properties to make your design
complete).

Q.3 Differentiate multiprocessing and multithreading in python using suitable points.

Q.4 Write a Python program to create a simple calculator.

Q.5 What is Client/Server Programming? Write a Python script to demonstrate it. Also, explain
the main functions used in it.

Q.6 What is mysql connector? How to access and connect with database using mysql connector?
Give and Explain steps with example

Q.7 Explain GUI in python and state its advantages and disadvantages.

Q,8 Write a python GUI that contains three Radio buttons for colors “Red”, “Green”, and
“Blue”. Display selected color on a label.
Q.9 Write a python program to insert a value in database table emp with following attribute
emp_id number, emp_name string, emp_sal number.

Q.10 What is grid layout? Give suitable example.

You might also like