25.07.2023 - 2 Programming for Problem Solving Using Python 2
25.07.2023 - 2 Programming for Problem Solving Using Python 2
Registration No.:
Instructions:
Answer question No. 1 (Part I) any ten out of 12 bits, from (Part II) any five out of 7 bits
and any two from (Part III) out of 4 bits.
The figures in the right-hand side margin indicate marks
Part – I Marks
0 Short Answer Type Questions (Answer any ten out of twelve) (02 x 10) BL C PO &
1 O PSO
a) Find out errors if any, otherwise show the output: 2 1 2
x=str (input ("Enter the first no: "))
y=float (input ("Enter the second no:"))
z=complex (input (“Enter the third number”))
print(x+y)
print(y+z)
print(x+y+z)
b “Python is dynamically typed, interpreted, portable and rich in 2 1 2
) library language,” justify your answer with an example.
c) What will be the output of the following code snippet? 1 1 3
a = [0.95674, 23.89645, 30.890,” GITA”,” Python”]
a = tuple(a)
a[0:2] = (2,7,8)
print(a)
d Write a program to display all the keywords of python 3 2 1
) programming language.
e) What is nested tuple? How to input it from the keyboard. 2 2 2
f) Find out errors if any, otherwise show the output: 2 3 3
def f1(x):
global a
print("f1:",a)
def f2(y):
global b
print("f2:",b)
a=19
b=789
f1()
f2()
g) Write a statement in python to open a file named “data.txt” 3 4 1
which is present in the following location in your computer:
E drive ->New Folder->Python->GITA->First Year
in read mode
h 2 4 2
What is the difference between error and exception?
)
i) What is Encapsulation? Explain with examples. 4 5 1
j) Define Polymorphism? 2 5 2
k Find out errors if any, otherwise show the output: 2 2 3
) import random
l=('b','n','h')
u1=random.choice(l)
u2=random.choice(l)
if ((u1=="b' and u2=="n")or (u1=="n" and u2=="b")):
print("Bear is the strongest")
elif ((u1=="b" and u2=="h")or(u1=="h" and u2=="b')):
print("Hunter is the strongest")
elif ((u1=="n" and u2=="h") or (u1=="h" and u2=="n")):
print("Ninja is the strongest")
elif ((u1=='b' and u2=='b') or (u1=='n' and u2=='n')or (u1=='h'
and u2=='h')):
print("No one is strongest')
else:
print("Your option is wrong")
l) Define empty dictionary in Python and how to input it from 3 1 2
keyboard
Part – II Marks
0 Focussed – Short answer type Questions (Answer any five out (04 x 05) BL C PO &
2 of seven) O PSO
a) Write a Python program to check whether a number is 3 2 5
palindrome or not without using loop.
b Find out errors if any, otherwise show the output: 2 3 4
) def sum(a=12,b=90,c=34.5):
d=a+b+c
print("Sum is", d)
sum()
sum(18)
sum(13,34)
sum(14,56,78)
c) Write down various techniques to convert a list to tuple and 3 1 5
vice versa.
d Write a recursive program as fact() to find the factorial of given 2 3 4
) no.
Example: -
Input: ‘n’ value 5
Output: Factorial of 5 = 120
e) WAP to demonstrate constructor with default argument. 2 5 5
f) Write a Python class as revr(), that reverse a word and return 1 4 5
the reverse without using inbuilt function.
Example:
input value: “Bijupattanaik”
Return value of function: “kianattapujiB”
g) List all the types of operators supported by python language 1 1 5
0 a) Illustrate the concept of hard copy, deep copy, and shallow copy 3 2 4
6 in python.
b Write a python program to input your mobile number as string, 2 3 5
) and convert each digit in that string into word. Insert these words
sequentially into a list.
Hint: -
INPUT: ‘9867452390’
OUTPUT: L= [‘nine‘, ‘eight’,
‘six’,‘seven’,‘four’,’five’,’two’,’three’,’nine’,’zero’]
NB: BL – Blooms Level 1, 2, 3, CO – Course Outcome, PO – Program Outcome, PSO – Program Specific
Outcome