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

Python Merged

The document outlines the examination structure for the Introduction to Python Programming course at B.M.S. College of Engineering, detailing the course code, duration, and maximum marks. It includes instructions for answering questions from various units, with specific programming tasks and concepts to be demonstrated. Each unit contains multiple questions focusing on different aspects of Python programming, such as loops, string manipulation, classes, and file handling.

Uploaded by

divyashree
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)
2 views

Python Merged

The document outlines the examination structure for the Introduction to Python Programming course at B.M.S. College of Engineering, detailing the course code, duration, and maximum marks. It includes instructions for answering questions from various units, with specific programming tasks and concepts to be demonstrated. Each unit contains multiple questions focusing on different aspects of Python programming, such as loops, string manipulation, classes, and file handling.

Uploaded by

divyashree
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
You are on page 1/ 6

U.S.N.

B.M.S. College of Engineering, Bengaluru-560019


Autonomous Institute Affiliated to VTU

February / March 2024 Semester End Main Examinations

Programme: B.E. Semester: I / II


Branch: Common to all Branches Duration: 3 hrs.
Course Code: 22CS1ESPYP / 22CS2ESPYP Max Marks: 100
Course: Introduction to Python Programming

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

1 a) Write a python code to demonstrate the working of a simple CO3 PO3 6


calculator.
b) Write a Python program to input student name, marks1, marks2 CO3 PO3 7
marks3 and USN. Calculate the percentage. Display “Excellent”
if percentage is >90, “Very Good” if percentage is in between 80
to 90, “Good” if percentage is in between 70 to 80. Print “Improve
if none of the above specified condition is met.
pages. Revealing of identification, appeal to evaluator will be treated as malpractice.

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

Use appropriate looping in each of the functions and display the


patterns.

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.

i. Create classes for wallets, transaction, and users.


ii. The wallet class should include methods for adding funds,
making payments, and displaying transaction history.

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.

B.M.S. College of Engineering, Bengaluru-560019


Autonomous Institute Affiliated to VTU

May 2023 Semester End Main Examinations

Programme: B.E. Semester: I


Branch: Common to all Branches Duration: 3 hrs.
Course Code: 22CS1ESPYP Max Marks: 100
Course: Introduction to Python Programming Date: 08.05.2023

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

1 a) Justify whether Python is procedural or object-oriented programming 6


language.
b) Consider the code given below. Analyze, identify the problem & correct the 6
code.
1. print("Python is a scripting language")
2. print("Python can be used as a procedural or object-oriented
programming language")
pages. Revealing of identification, appeal to evaluator will be treated as malpractice.

3. print(“PYTHON is interpreted language")


4. Errors = 10
5. Sum= 0
6. Logic = 3
7. while syntax!=0:
8. Sum+= 1
9. Syntax -= logic
10. print("Python is a dynamic typed language,)
11. print("Python is the most preferred language for gaming
applications")
c) A pangram is a sentence that contains all the letters of the English alphabet at 8
least once, for example: “The quick brown fox jumps over the lazy dog”.
Write a Python program to check a sentence to see if it is a pangram or not.
UNIT – II
2 a) Write a program, which will find all such numbers between 1000 and 3000 6
(both included) such that each digit of the number is an even number. The
numbers obtained should be printed in a comma-separated sequence on a
single line.
b) Use a list comprehension to square each odd number in a list. The list is input 8
by a sequence of comma-separated numbers.
Suppose the following input is supplied to the program:
1,2,3,4,5,6,7,8,9
Then, the output should be:
1,3,5,7,9
c) Write a Python program to get a list, sorted in increasing order by the last 6
element in each tuple from a given list of non-empty tuples.
Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
Expected Result : [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]

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))

dict1 = {'a': 10, 'b': 8}


dict2 = {'d': 6, 'c': 4}
print(Merge(dict1, dict2))
print(dict2)
c) Write a Python program to find the maximum and minimum value in a tuple 8
UNIT - IV
5 a) Demonstrate how inheritance supports reuse with a suitable example. 6
b) Demonstrate how exceptions are handled in Python with a suitable example. 8
c) Write a Python class to get all possible unique subsets from a set of distinct 6
integers.
OR
6 a) Demonstrate with an example how multiple except blocks can be written for a 8
single try block to handle multiple exceptions.
b) Create a Vampire class that has one class attribute and two attributes. The 12
class attribute is a tuple holding the following hunger levels:
“stuffed”,”full”,”peckish”,”hungry”, and “starving”. The two attributes need
to hold the name and the hunger. The hunger is an integer that will be used as
an index into the hunger levels tuple.
i. Define a constructor (__init__) that has one parameter for the name.
ii. Create a method (__str__) to be able to print the object. Use the hunger
levels and hunger attributes.
iii. Create a suckBlood method that will decrease the hunger by 1.
iv. Create a main function. In this function, create a list of human objects. You
can hard code the data. Let the user enter his/her name and create a Vampire
Object.
v. Create a menu function to allow the user to print the humans and suck
blood.
vi. Create a function to print the humans. To do this, use the enumerate
function to print an index number or each human and then his/her info.
vii. Create a function to suck blood. This will ask the user to enter an index
number of a human. It will then call the suckBlood method on the human and
the vampire (provided the human had some blood left).
viii. Please add error checking(exceptional handling) and comments

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()

b) Demonstrate serialisation operation of files with a suitable example. 5


c) Analyze the program, find the error and write the correct program to get the 5
output given below:
#PROGRAM
text_file = open("c.txt", "a+")
text_file.write("Line 1\n")
text_file.write("This is line 2\n")
text_file.write("That makes this line 3\n')
lines = ["L1\n","L2";"L3\n"]
text_file.write(lines)
a=text_file.read()
print(a)
text_file.close()
OUTPUT:
Line 1
This is line 2
That makes this line 3
L1
L2
L3

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).

******

You might also like