0% found this document useful (0 votes)
241 views3 pages

Python Programming Exam Paper 2023-24

Uploaded by

26aiindda
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)
241 views3 pages

Python Programming Exam Paper 2023-24

Uploaded by

26aiindda
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

Printed

Code: BCC302
PAPER ID-311224
Subject
Roll No:

BTEC!1
22oosoolo8
(SEM II) THEORY EXA
PYTHON MINATION 2023-24
TIME: 3HRS PROGRAMMING
[Link]: 70
Note: 1. Attempt all Sections. It require any missing
data: then choose
suitably
STCTION A
1. Attempt all questions in brief.

|Qno
Qustio
Marks
Deseribe the concept [Link] comprehenion with suitable exannpie

ia
Differeniate between and // operator NIth an cxample

/
C
Compute the output of the following p thon code:
2
def count(s):

for str in [Link]):

S
"&"join(str)
returns

print(count("Pythonis fun to learn.")


How to use the functions defined in [Link] in [Link] 2
e Describe the difference between linspace and argspace.
f Explain why the program generates an error. 2
X -[12, hello', 456]
x[0] *= 3
x[1I[1]-°bye'
Describe about different functions of matplotlib and pandas.
SICTION B
2. Attempt any iree o1 the tolloWIng:
a.
Illustrate Unpacking tuples, mutable sequences, and sring concatenation with7
examples
Illustrate different list slicing constructs for the following operations on the
following list:

L-[1,2, 3.4, 5, 7, 8,9]


6.,
1. Return a list of numbers starting from the last to second item of the list
2. Return a list that start from 3rd item to second last item.
3. Return alist that has only even position elements of list L to list M.
4. Return a list that starts from the middle of the list L.
5. Return a list that reverses all the
clements starting from element at index
0 to middle index only and return the entire list.

Divide cach clement of the list by 2


and replace it with theremainder
C.
Construct a function perfevt square{nunnber) that
returnsa number ifit is a perfect 7
square otherwise ii returns -1.
For exanmple:
perfcct square(I) returns
I
perfect square (2) reiurns -1
Construct a program to change the contents of the file by reversin: cach character7
separated by comma:
Hello!!

Output

H.e,l.l.o,!,!

VC. Construct a plot for following dataset


using matplotlib 7
1|2e

Galaxy A23
Printed Page: 2 of 3
PAPERID-311224 Subject Code: BCC302
Roll No:

BTECH
(SEM II) THEORY
EXAMINATION 2023-24
PYTHON PROGRAMMMING
TIME: 3HRS 70
[Link]:

Food Calories Potassiun ial

Meat 250 40 8
Banana 130 55
Avocados 140 20
Sweet
Potatoes 120 30 6
Spinach 20 40

1
Watermelon 20 32 1.5

Coconut
water 10 10
Beans 50 26 2
Legumes 40 25 1.5

Tomato 20 2.5
SECTION C
3.
Attempt any one part of the following:
a.
Determine a pvthon function remove1i(s,n) that takes an input a string and an
integer n>=0and removes a character at index n. Ifn is beyond the length of s.
then whole s is returned. For example:

removenth("MANGO", 1)returns MNGO


removenth("MANGO",3) returns MANO

Construct a program that accepts a conima separated sequence of words as input


and prints the words in a comma-separated sequence after sorting them
alphabetically.
Suppose the following input is supplied to the program:
without. hello, bag. world
Then, the output should bc:

bag, hello, without, world


4
Attempt any one part of the following:

A website requires the users to input usename and passwordto registcr. Construct 7
a program to check the validity of passvord input by users.

Following are the criteria sorcheckingne password:


1. At least 1 letter between [a-z]
2, At least 1 number between [0-91
3. At least 1 letterbetween [A-Z]
4. At least I character from [S#@]
5. Minimum length of transaction password: 6
6. Maximum length of transaction password: 12

Your program should accept a sequenceof comma separated passwords and will
check them according to the above criteria. Passwords that match the criteria
are
to be printed, cach separatcd by a
comrma
b. Explorethe working of while, and for loop with examples.
5. Attempt any one part of the following:

Galaxy A23 2|e


PrinteTage
Code:
BCC302
PAPER ID-311224 Subject
Roll No:
BTECH
(SEM II) THEORY EXAMINATION
2023-24
TIME: 3HRS PYTHON PROGRAMMING
[Link]: 70
a Construct a function ret smaller(l) that returns smallest
two lists have same length then
list from a nested list. If7
return the first list that is encountered. For
example:

ret smaller(| [-2, -1, 0, 0.12, 1, 21. (3.1, 51. [6.7,8,9. 101,(11,12, 13, 14, 1511)

returas [3,4,5)
ret smaller([ -2, -1, 0, 0.12, 1, 2], ['a, "b', 'c,d', 3, 4, 5], [6,7,8,9, 10], (11,
[
12, 13,14,15]])) returns [6,7, 8,9, 1O
7
b Construct following filters:

1. Filter all the numbers


all the strings starting with a vowel
2. Filter
contains any of the following noun: Agra,
3. Filter all the strings that

Ramesh, Tomato,Patna.
to clean the text.
Create program that inmplements these
a
tilters

6. Attempt any one part of the following:


to text. Construct a program for the same.
the numbers in the file
Change all

Example:
the product is equal to or lower
product only if
Given 2 integer numbers, return their
than 10.
And the result should be:
the product is equal to or
return their product only if

Given two integer numbers,


lower than one zero
separated by whitespace7
Construct program which accepts a sequence of words
a

input. Print the words


composed of digits only.
as file

of the following:
7. Attempt any one part
remove last column and save
it in

Construct aprogram to read [Link] datasct,


array. Plot the first two columns.
a.

an array. Save the last column to another


with the following buttons
and functionalities like addition.
b. Design a calculator
division and clcar.
subtraction, multiplication,
Calculator

Galaxy A23 31a

Common questions

Powered by AI

To create a program for this task, split the input string by commas, sort the resulting list, and then rejoin it: `def sort_words(input_sequence): words = input_sequence.split(','); words.sort(); return ','.join(words)`. Calling `sort_words('without, hello, bag, world')` will yield 'bag, hello, without, world'.

To construct such a program, read the file's content, reverse the string, and insert commas: `def reverse_characters(file_path): with open(file_path, 'r') as file: content = file.read(); reversed_content = ','.join(reversed(content)); with open('output_file.txt', 'w') as output: output.write(reversed_content)`. This reads, processes, and writes the transformed content to a new file.

Unpacking tuples involves assigning elements of a tuple to variables. For example, given `t = (1, 2, 3)`, executing `a, b, c = t` assigns 1 to a, 2 to b, and 3 to c. For mutable sequences, you can unpack like so: `lst = [4, 5, 6]`, and `d, e, f = lst` assigns 4 to d, 5 to e, and 6 to f. Unpacking is useful for multiple assignment in a single statement.

In Python, the `/` operator performs floating-point division, which returns a float result, while the `//` operator performs floor division, returning an integer result by discarding the fractional part. For instance, `7 / 3` yields `2.3333`, and `7 // 3` yields `2`.

To use functions from `library.py` in `main.py`, import the desired functions using the import statement. Place `library.py` in the same directory or ensure its path is accessible. In `main.py`, utilize `import library` to import all functions or `from library import specific_function` to import specific ones. Then call the imported functions within `main.py`.

The password validation criteria require these conditions: at least one lowercase letter, one uppercase letter, one digit, one special character from [@$#], and a length between 6 and 12. Validating involves checking each condition using regex: `import re; def validate_password(password): conditions = [r'(?=.*[a-z])', r'(?=.*[A-Z])', r'(?=.*\d)', r'(?=.*[@#$])', r'.{6,12}$']; return all(re.search(cond, password) for cond in conditions)`. This function checks all validations with regular expressions.

`linspace` is a function in NumPy used to generate evenly spaced numbers over a specified range, useful for plotting graphs or creating data arrays. However, `argspace` is not a standard function in Python libraries and may refer to user-defined utilities, which means it does not exist by default in modules like NumPy. Context usually defines `argspace`.

The error occurs because `x[1]` is a string ('hello'), and the assignment `x[1][1] = 'bye'` tries to modify an immutable string's character, which is not allowed in Python. Strings do not support item assignment.

The function can be implemented by determining if the square root of the number is an integer: `def perfect_square(number): import math; root = math.sqrt(number); return number if root.is_integer() else -1`. This checks the integer nature of the root to determine perfect square status.

List comprehension offers a concise way to create lists in Python. It can generate a new list by applying an expression to each item in an iterable, optionally filtering items using a condition. For example, consider generating a list of squares for the numbers 1 to 5: `[x**2 for x in range(1, 6)]`. This results in the list `[1, 4, 9, 16, 25]`.

You might also like