0% found this document useful (0 votes)
20 views7 pages

Python Programming Exam Questions 2022

This document contains 10 questions from 5 units on Python programming for a technical exam. The questions cover key topics like Python features, operators, conditional and loop statements, strings, lists, functions, modules, file handling, exceptions, GUI programming and Scratch. Students must answer 5 questions by selecting 1 question from each unit, with all questions carrying equal marks.

Uploaded by

Bad Bᝪγ Gamer
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)
20 views7 pages

Python Programming Exam Questions 2022

This document contains 10 questions from 5 units on Python programming for a technical exam. The questions cover key topics like Python features, operators, conditional and loop statements, strings, lists, functions, modules, file handling, exceptions, GUI programming and Scratch. Students must answer 5 questions by selecting 1 question from each unit, with all questions carrying equal marks.

Uploaded by

Bad Bᝪγ Gamer
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

Code No: R201225 R20 SET - 1

I B. Tech II Semester Regular/Supplementary Examinations, August- 2022


PYTHON PROGRAMMING
(Com. To CSE, IT, CSE-AI&ML,CSE-AI, CSE-DS, CSE-AI&DS, AI&DS)
Time: 3 hours Max. Marks: 70
Answer any five Questions one Question from Each Unit
All Questions Carry Equal Marks
Unit - I
1 a) List out and explain the key features of Python programming. (7M)
b) What is a Conditional statement in Python programming? Give the syntax of (7M)
various Conditional structures available in Python programming.
Or
2 a) How to access the characters in Python String? Write a Python program to (7M)
demonstrate it.
b) Write a Python program to demonstrate the usage of Logical, Membership and (7M)
Identity operators.
Unit - II
3 a) Write the syntax of various Loop statements supported by Python programming and (10M)
explain their execution behavior with neat flow diagrams.
b) How to Encrypt and Decrypt Strings in Python? Explain with an example. (4M)
Or
4 a) Write a Python program to demonstrate the usage of common Python String (7M)
methods.
b) Develop a Python program to display the Fibonacci series between 0 and 100. (7M)
Hint : The Fibonacci Sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, 13, …
Unit - III
5 a) List out various Python List Built-in methods and write a program to demonstrate (7M)
their usage.
b) Write a Python function to print the even numbers from a given list. (7M)
Or
6 a) Develop a Python program to access the elements of a Nested dictionary. (7M)
b) What are Python modules? Explain the steps to import specific attributes from a (7M)
module into the current Namespace with appropriate code snippets.
Unit - IV
7 a) Explain the prototypes of read(), readline() and readlines() functions in Python. (7M)
b) Write about Class Inheritance and demonstrate the usage of issubclass() and (7M)
isinstance() methods in Python.
Or
8 a) How do you manipulate a file pointer in Python? Explain with a sample program. (7M)
b) Does Python Support Operator overloading? Justify. (7M)
Unit - V
9 How to create, raise and handle user defined exceptions in Python? Illustrate with a (14M)
Python program.
Or
10 a) Give the syntax to create Radiobutton widget. And write a Python program to create (7M)
Radiobuttons for selecting the Gender(Male, Female, Transgender) on the same
canvas.
b) What type of programming is Scratch? What are the different kinds of Scratch (7M)
blocks?
1 of 1
|''|''|||''|'''|||'|
Code No: R201225 R20 SET - 2
I B. Tech II Semester Regular/Supplementary Examinations, August- 2022
PYTHON PROGRAMMING
(Com. To CSE, IT, CSE-AI&ML,CSE-AI, CSE-DS, CSE-AI&DS, AI&DS )
Time: 3 hours Max. Marks: 70
Answer any five Questions one Question from Each Unit
All Questions Carry Equal Marks
Unit - I
1 a) List out various operators available in Python and explain their precedence and (7M)
associativity
b) Write a python program to calculate the total amount to be paid by user after (7M)
reducing the 10% discount on purchases more than 1000 rupees.
Or
2 a) Discuss various Python Built-in functions for manipulating Strings. (7M)
b) Explain the syntax of different Nested Decision structures in Python (7M)
programming.
Unit - II
3 a) Explain the execution behavior of ‘for’ loop statement supported by Python (7M)
programming with an example program.
b) Elaborate the sequence of steps to encrypt and decrypt Strings in Python. (7M)
Or
4 a) Write a Python program that prints all the numbers from 0 to 100 except the (7M)
multiples of 4 and 6.
b) Compare and Contrast Pre-test and Post-test loop structures in Python (7M)
programming.
Unit - III
5 a) Discuss various ways to access the elements of a List in Python with appropriate (7M)
code snippets.
b) What is a Lambda function in Python? What are the benefits of Lambda function (7M)
in Python? Demonstrate its usage through a sample program.
Or
6 a) Explain the steps to create a Dictionary in Python and list out Dictionary Built-in (7M)
functions.
b) Write about the following features in Python programming (7M)
i)Modules ii) globals() and locals() Functions iii)Packages

Unit - IV
7 a) Explain the steps to read config files and write Log files in Python. (7M)
b) What are the different modes of opening a file in Python? Explain the Python (7M)
‘open()’ built-in function.
Or
8 a) Explain about write() and writelines() functions in Python. (7M)
b) Write Python code snippets to illustrate Method overriding and Method (7M)
overloading concepts.

1 of 2

|''|''|||''|'''|||'|
Code No: R201225 R20 SET - 2

Unit - V
9 a) Write a Python program to handle Division By Zero exception. (7M)

b) Explain the purpose of ‘else’ and ‘finally’ blocks in exception handling with a (7M)
Python program.
Or
10 a) Write a Python GUI program to create three single line text-box to accept a value (7M)
from the user using tkinter module
b) Explain in brief the four main elements of Scratch programming environment. (7M)

2 of 2

|''|''|||''|'''|||'|
Code No: R201225 R20 SET - 3
I B. Tech II Semester Regular/Supplementary Examinations, August- 2022
PYTHON PROGRAMMING
(Com. To CSE, IT, CSE-AI&ML,CSE-AI, CSE-DS, CSE-AI&DS, AI&DS )
Time: 3 hours Max. Marks: 70
Answer any five Questions one Question from Each Unit
All Questions Carry Equal Marks
Unit - I
1 a) Describe the features of Python that made it so popular. (7M)
b) List out and explain Comparison, Identity and Membership operators in Python (7M)
programming.
Or
2 a) Write a Python program to demonstrate the usage of all specifiers available with (7M)
format() method.

b) Elaborate on various Conditional structures in Python programming and explain (7M)


the syntax of each.
Unit - II
3 a) Write a Python program to construct the following pattern, using a nested for loop. (7M)
*
**
***
****
*****
****
***
**
*
b) What is meant by Data Encryption? What are its types? What are the libraries (7M)
available in Python for Data Encryption?
Or
4 a) Write a Python program to demonstrate the usage of Loop control statements (7M)
available in Python programming.
b) How to write a String to a text file in Python? Explain with a sample program. (7M)

Unit - III
5 a) Explain about Negative indexing and List Slicing in Python with a sample (7M)
program.
b) Write a Python function to check whether a number is perfect or not. (7M)
Or
6 a) Explain the steps to access the elements of a Dictionary using various Built-in (7M)
functions.
b) Write a Python program to extract characters from various text files and puts them (7M)
into a List.

1 of 2

|''|''|||''|'''|||'|
Code No: R201225 R20 SET - 3

Unit - IV
7 a) Write about read () and write () methods in Python programming. (7M)
b) Explain the prototype of seek () function in Python and write a program to (7M)
demonstrate its usage.
Or
8 a) Describe the steps to create Classes and Objects in Python. List out the Built-in (7M)
Class attributes.
b) When do we need a separate configuration file? Explain the steps for writing, (7M)
reading and extracting values from config files in Python.
Unit - V
9 a) Briefly discuss various keywords related to Exception handling in Python (7M)
programming.
b) Write a python program to illustrate the cases where a try block throws multiple (7M)
exceptions.
Or
10 a) Write a Python GUI program to create Listbox bar widgets using tkinter module. (7M)
b) How to create Option Menu using tkinter in Python? Illustrate with a program. (7M)

2 of 2

|''|''|||''|'''|||'|
Code No: R201225 R20 SET - 4
I B. Tech II Semester Regular/Supplementary Examinations, August- 2022
PYTHON PROGRAMMING
(Com. To CSE, IT, CSE-AI&ML,CSE-AI, CSE-DS, CSE-AI&DS, AI&DS )
Time: 3 hours Max. Marks: 70
Answer any five Questions one Question from Each Unit
All Questions Carry Equal Marks
Unit - I
1 a) Draw a table to describe the precedence and associativity of Python operators. (5M)
b) Write a Python program to find those numbers which are divisible by 5 and (9M)
multiples of 3, between 1 and 1000.
Or
2 a) Explain the Python built-in functions to perform data type conversions. (7M)
b) Explain the execution behavior of various Decision making statements available in (7M)
Python programming with neat flow diagrams.
Unit - II
3 a) Give the syntax of various Loop statements supported by Python programming. (7M)
b) Write a Python program to get substring between characters in the input. (7M)
Or
4 a) Write a Python program to compute the natural logarithm of 2, by adding up to n (7M)
terms in the series 1 – ½+ 1/3 – ¼ + 1/5 -… 1/n
where n is a positive integer and input by user.
b) Develop a Python program to search the string ‘laptop’ in “[Link]” file and print (7M)
its line along with the line number.
Unit - III
5 a) Discuss various ways to create Lists in Python and Write a program to illustrate (7M)
Negative index List slicing.
b) What is an Anonymous function and when should you use it? How Anonymous (7M)
function is different from normal function?
Or
6 a) Write the properties of Dictionary Keys in Python. And explain how to access, (7M)
delete and update Dictionary elements.
b) Explain the steps to install, search, upgrade and uninstall a package in Python with (7M)
‘pip’.
Unit - IV
7 a) Explain the steps for reading and writing config files in Python. (7M)
b) Describe the Python Built-in function for opening, reading, writing and closing (7M)
files.
Or
8 a) Write a Python program to create a class ‘student’ with members {name, branch, (7M)
grade}. Define appropriate member functions for reading and displaying the
student information.
b) How can polymorphism be implemented in Python? Illustrate with a code snippet. (7M)

1 of 2

|''|''|||''|'''|||'|
Code No: R201225 R20 SET - 4

Unit - V
9 a) List and explain any 12 Built-in Exceptions available in Python. (7M)
b) Explain the usage of ‘except’ clause in Python with multiple exceptions and no (7M)
exceptions.
Or
10 Explain the syntax and parameters of the following Widgets using tkinter in (14M)
Python with appropriate code snippets.
i)Scrollable List Box
ii)Menu
iii)Progress bar

2 of 2

|''|''|||''|'''|||'|

Common questions

Powered by AI

Operator overloading in Python allows developers to change the way operators work with user-defined data types, thereby enhancing flexibility and intuitiveness of classes. By defining methods like __add__ or __sub__, custom behaviors are achievable, making the code more semantic and easier to read, as it allows operations to be used between objects meaningfully and succinctly. For example, multiplying two vectors could use * operator, making mathematical operations readable and more concise .

The seek() method in Python is used for file manipulation, to change the cursor position in the file for subsequent reads and writes. Its typical use cases include random file access where repeated accesses to specific file parts are needed, such as database management systems or processing large data files. Example: with open('file.txt', 'rb') as f: f.seek(5) reads starting 5th position following 'file.txt' .

Handling user-defined exceptions in Python involves creating a class derived from 'Exception', defining its __init__ method to accept error details, and using a try-except block to raise and react to it. This is significant as it helps create robust code that can handle domain-specific errors, enhancing error reporting, allowing for appropriate recovery, and containing systemic errors that could otherwise cause application shutdowns. Example: class InputError(Exception) helps custom error notifications .

Python is popular due to its simple and easy-to-learn syntax which promotes readability and reduces the cost of program maintenance. It supports modules and packages, which encourages program modularity and code reuse. Python is also an interpreted language, which can run without compilation, and it carries a large standard library that supports many common programming tasks. Additionally, Python supports dynamic typing and automatic memory management .

The 'finally' block in Python is used to execute code regardless of whether an exception occurs, typically used for cleanup actions like closing files or releasing resources. This ensures the block executes even if an exception is not handled. For example: try: file = open('file.txt', 'r'); except IOError: print('File not found error'); finally: file.close() ensures the file closes following an IOError, demonstrating resource management .

To encrypt and decrypt strings, Python offers libraries such as 'cryptography'. For example, using the Fernet module from the cryptography library: 1) Install the library using 'pip install cryptography'. 2) Import Fernet and use 'Fernet.generate_key()' to generate a secure key. 3) Use 'Fernet(key).encrypt(message)' for encryption and 'Fernet(key).decrypt(encrypted_message)' for decryption. This manages secure byte conversions to ensure safe transfer and retrieval of information .

In Python, the pre-test loops are 'for' and 'while', which test their condition at the beginning; if the condition is true, the loop body executes. The 'for' loop iterates over items of a sequence, while 'while' continues as long as the test condition is true. Python lacks an explicit post-test loop structure, like do-while in other languages, where the loop executes at least once before the condition is tested. Any emulation of such behavior in Python would require an explicit setup using 'while True' and an if-break condition pair, introducing complexity and risk of errors .

Lambda functions in Python are small anonymous functions defined using the 'lambda' keyword. They can take any number of arguments but have a single expression. They are syntactically restricted to a single expression and are useful for quick, throwaway functions. Lambda functions are beneficial for short-term use, where traditionally a full function definition would be overkill. Example: lambda x: x * x, which squares an input, can be used inline with map or filter functions for concise code .

Accessing elements in a nested dictionary involves indexing each level of the hierarchy. Suppose 'd' is a nested dictionary like d = {'key1': {'key2': 'value'}}. To access 'value', index using both keys: 'd['key1']['key2']'. To safely traverse a nested dictionary, it's prudent to use the 'get' method, which permits safe navigation by supplying default values, thus: 'd.get('key1', {}).get('key2')' .

Conditional structures in Python include 'if', 'elif', and 'else' statements. The 'if' statement checks a condition and executes a block of code if the condition is true. The 'elif' statement allows checking multiple expressions for true and executes a block as soon as one is true, serving as an alternative to the 'if' with another condition. The 'else' keyword catches anything not caught by the preceding conditions. Each block of code is defined by its indentation .

You might also like