t2 a Qp Python-i Sem-III 2022
t2 a Qp Python-i Sem-III 2022
L. J. UNIVERSITY Set: Z
L.J. INSTITUTE OF ENGINEERING AND TECHNOLOGY, AHMEDABAD
TEST 2
B.E. SEMESTER-III BRANCH: CE/IT/CSD/AIML/AIDS/RAI/CSE
SUBJECT- FUNDAMENTALS OF COMPUTER SCIENCE USING PYTHON - I
SUBJECT CODE: 017012391,017022391,017032391,017042391,017052391,017062391,017122391
DATE: 02-Jan-23 DURATION: 2.25 Hours
TIME: 03:30 PM To 05:45 PM MAX MARKS: 25 marks
Instructions
* All questions are compulsory.
* Figure to the right indicates marks
* Assume suitable additional data if necessary and mention them.
Q-1 A)
def current_date(**kwargs):
for i in kwargs:
print(i)
current_date(date=2-1-2023)
my_tuple = (1, 2, 3, 4)
my_tuple.append( (1,2,3) )
print (len(my_tuple))
a) 4 b) 7 c) 5 d) 1
e) 2 f) 3 g) Error
6) What will be the output of the following Python code? [0.5]
def writer():
title = 'Sir'
name = (lambda x: title + ' ' * 2x)
return name
who = writer()
print(who('Arthur'))
a) 400 1 5 b) 400 4 5 c) 25 2 5 d) 25 2 30 e) 25 4 30
f) Syntax Error g) 400 2 30
8) What will be the output of the following Python code? [0.5]
a) 10 11 11 13 b) 10 12 12 13 c) 12 d) 12 13
e) 10 11 12 13 f) Attribute error g) Syntax Error
Q-1 B)
a = [5,5,6,7,7,7]
b = set(a)
def test(lst):
if lst in b:
return 1
else:
return 0
for i in filter(test, a):
print(i,end=" ")
a) 1 b) 5 6 7 c) 0 d) 5 5 6 7 7 7
e) 5 5 6 f) 5 6 7 7 7 g) Error
3) What will be the output of the following Python code? [01]
s1={3, 4}
s2={1, 2}
s3=set()
i=0
j=0
for i in s1:
for j in s2:
s3.update((i,j))
i+=1
j+=1
print(s3)
def enc(st):
encoded=""
c=1
ld=st[0]
for i in range (1,len(st)):
if ld==st[i]:
c=c+1
else:
encoded=encoded+str(c)+ld
c=0
ld=st[i]
c=c+1
encoded=encoded+str(c)+ld
return encoded
st="AAABBACCAA"
print(enc(st))
a) 3A2B1A3C2A b) AAABBACCAA c) A3B2A1C3A2 d) 3A2B1A2C2A
e) A3B2A1C2A2 f) 10 g) Error
5) What will be the output of the following Python code? [01]
names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
names2 = names1
names3 = names1
names2[0] = 'Alice'
names3[1] = 'Bob'
sum = 0
for ls in (names1, names2, names3):
if ls[0] == 'Alice':
sum += 1
if ls[1] == 'Bob':
sum += 10
print(sum)
a) 12 b) 11 c) 32 d) 33 e) 22 f) 21 g) 20
6) What will be the output of the following python code? [01]
car=20
bike=10
cycle=30
def new_Pur():
global bike,cycle
car=30
bike=20
cycle=50
new_Pur()
print(car+10," ",bike+5," ",cycle+5)
a) 40 25 55 b) 30 15 35 c) 30 25 35 d) 20 25 55
e) 25 20 50 f) 30 25 55 g) Syntax Error
Q-2 1) Write a Python programme that accepts a string and calculate the number of uppercase [03]
letters, lowercase letters and number of digits.
For example,
Output:
Uppercase letters : 2
Lowercase letters : 14
Digits : 3
2) Write a Python program using function to shift the decimal digits n places to the left, [03]
wrapping the extra digits around. If shift > the number of digits of n, then reverse the string.
Note:
Function will take two parameters:
1. The number
2. How much shift user want
Example:
Input: n=12345 shift=1
Output: Result=23451
Note: You are not allowed to use an extra iterable like list, tuple, etc. to do this. You
need to make changes in the given list A itself. Your program should be able to handle
any N x N matrix from N = 1 to N = 20.
Examples:
ALL THE BEST