0% found this document useful (0 votes)
10 views

Python Programming Procedural - Ba (Gad)_r22_supple-1

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

Python Programming Procedural - Ba (Gad)_r22_supple-1

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

Code No: U4GA22B2.

7GP

B.A - HONOURS (GAD) II SEMESTER (R22) SUPPLEMENTARY EXAMINATION, MARCH - 2024

PYTHON PROGRAMMING PROCEDURAL

Time: 3 Hrs Max. Marks: 50

Answer any three of the following: 3*10=30 Marks

1. Write a python program which reads n values into a list and performs the following
operations.

i. Insert a given value at given position into the list.


ii. Find third largest value from the list.

2. Write a program which reads n values and print the all possible patterns by perform-
ing left circular shift.

3. Write a Python Program to find roots of quadratic equation.

4. Write a Python program to impalement insertion sort.

5. Write a Python Program to read two text files one after the other and write the con-
tents to third file.

Here are brief solutions for each of your questions:

### 1. Read n Values and Perform Operations

```python

n = int(input("Enter number of values: "))

values = [int(input()) for _ in range(n)]

# i. Insert a value at a given position

value_to_insert = int(input("Value to insert: "))

position = int(input("Position: "))

values.insert(position, value_to_insert)
# ii. Find third largest value

third_largest = sorted(set(values))[-3]

print("Third largest value:", third_largest)

```

### 2. Left Circular Shift Patterns

```python

n = int(input("Enter number of values: "))

values = [input() for _ in range(n)]

for i in range(n):

print(values[i:] + values[:i])

```

### 3. Roots of Quadratic Equation

```python

import cmath

a = float(input("Enter a: "))

b = float(input("Enter b: "))

c = float(input("Enter c: "))

d = (b**2) - (4*a*c)

root1 = (-b + cmath.sqrt(d)) / (2*a)

root2 = (-b - cmath.sqrt(d)) / (2*a)


print("Roots:", root1, root2)

```

### 4. Insertion Sort

```python

def insertion_sort(arr):

for i in range(1, len(arr)):

key = arr[i]

j=i-1

while j >= 0 and key < arr[j]:

arr[j + 1] = arr[j]

j -= 1

arr[j + 1] = key

n = int(input("Enter number of values: "))

values = [int(input()) for _ in range(n)]

insertion_sort(values)

print("Sorted list:", values)

```

### 5. Read Two Text Files and Write to Third

```python

with open('file1.txt', 'r') as f1, open('file2.txt', 'r') as f2, open('file3.txt', 'w') as f3:

f3.write(f1.read())
f3.write(f2.read())

```

Let me know if you need anything else!

Viva-voce: 20 Marks
***

You might also like