Python Merged
Python Merged
Instructions: 1. Answer any FIVE full questions, choosing one full question from each unit.
2. Missing data, if any, may be suitably assumed.
UNIT - I CO PO Marks
Important Note: Completing your answers, compulsorily draw diagonal cross lines on the remaining blank
c) Explain the working of for and while loop in detail with CO1 PO1 7
appropriate code snippets.
UNIT - II
2 a) Write a program to create a new string made of an input string’s CO1 PO1 6
first, middle, and last character.
b) Write a python program to remove the nth character from the CO3 PO3 7
given string. (Take n from the user)
c) Write a Python program to print the largest number from a list of CO3 PO3 7
numbers entered by the user. (Do not use the inbuilt function max)
UNIT - III
3 a) Write a program to count the frequency of occurrence of each CO3 PO3 5
character in a given string. Use a dictionary to store the character
as key and the number of occurrences as value.
b) Write a python program to identify duplicate values in a tuple. CO3 PO3 5
c) Write a python code to include the following functions: CO1,3 PO1,3 10
Function star()
- Prints the pattern
Function hash()
- Prints the pattern
Function num_pattern()
- Prints the pattern
OR
4 a) The college decides to give scholarship to students scoring a CO3 PO3 5
CGPA of more than 9.0. Given a dictionary containing
USN:CGPA as key value pairs, write a python program to create
a new dictionary containing the details of students eligible for
scholarship.
b) Write a python program to remove an element from a tuple. CO3 PO3 5
c) Write a python code to include the following functions. The CO1,3 PO1,3 10
purpose is to plan a budget for a trip.
Function 1: travel()
- Ask the user for number of kilometres.
- Travel charges in bus is 20 per km and that in car is 15 per km.
Function 2: shopping()
- Each item costs Rs 500.
- Ask the user for the number of items he plans to buy.
Function 3: amusement()
- If the user wants to ride in less than 5 rides the cost is 200 else
its 300
Call these functions and print out the total cost of the user’s trip.
UNIT - IV
5 a) Create a class Employee to have the following: CO3 PO3 10
• Variables name, emp_id, designation
• A constructor to initialize these values
• A method salary_calc that accepts basic salary as
parameter, adds 10000 if designation is “Clerk” and adds
12000 if designation is “Manager”.
Create 3 objects and call the appropriate method.
b) Explain operator overloading and demonstrate the overloading of CO1 PO1 10
+ and * operators using appropriate code.
OR
6 a) Develop a python program to create a digital wallet system. The CO3 PO3 10
system should include the following features.
b) Create a main class car. Formulate two child classes electric car, CO3 PO3 10
and petrol car. The child class should include the attributes like
make, colour, price and range.
UNIT - V
7 a) Write a program to read a file and print the number of lines, words CO3 PO3 6
and characters in the file.
b) Write a program to write the content “It is a lovely day” into the CO3 PO3 6
file. Also append the line “Be good, do good” to the same file.
c) Describe regular expressions and elaborate on findall(), search(), CO1 PO1 8
sub() and split() methods with sample code for each.
******
U.S.N.
Instructions: 1. Answer any FIVE full questions, choosing one full question from each unit.
2. Missing data, if any, may be suitably assumed.
UNIT - I
Important Note: Completing your answers, compulsorily draw diagonal cross lines on the remaining blank
UNIT - III
3 a) Illustrate with an example function call and passing arguments to a function in 6
Python.
b) Demonstrate with an example the advantages of sequence packing and 6
unpacking of tuples.
c) Write a Python program for the following scenario: 8
Given an array of names of candidates in an election. A candidate name in the
array represents a vote cast to the candidate. Print the name of candidates
received Max vote. If there is tie, print a lexicographically smaller name.
OR
4 a) Given a list of elements, perform grouping of similar elements, as different 6
key-value list in dictionary.
Sample Input : test_list = [4, 6, 6, 4, 2, 2, 4, 8, 5, 8]
Output : {4: [4, 4, 4], 6: [6, 6], 2: [2, 2], 8: [8, 8], 5: [5]}
b) Analyse the following code and write the output with suitable justification: 6
def Merge(dict1, dict2):
return(dict2.update(dict1))
UNIT - V
7 a) Suppose we have created a file with 500 lines of data and the the file object 5
reference is “f”.
Illustrate what each of these following operations does:
(i) F.seek(0)
(ii) F.seek(100,1)
(iii) F.seek(-10,2)
(iv) F.seek(0,2)
(v) F.tell()
d) Write a program that will calculate the average word length of a text stored in 5
a file (i.e the sum of all the lengths of the word tokens in the text, divided by
the number of word tokens).
******