Class 12 - Python Functions Question Bank 3
Class 12 - Python Functions Question Bank 3
In the next section of important QnA python library functions 12 you will find some output questions.
Q – 9 Find the output for the following:
1.
def str_exp():
str1= 'COVID-19,Sanitizer,Mask,LockDown'
str1=str1.lower()
str2 =str1.split(',')
for i in str2:
if i<'s':
print(str.lower(i))
else:
print(str.upper(i))
str_exp()
Answer:
covid-19
SANITIZER
mask
lockdown
In the above example, the text starts with the alphabet ‘s’ and letter coming after ‘s’ will be converted into uppercase and rest text will be in
lower case.
2.
def str_exp():
str1='Covid - 19 forces the entire worl to be lockdown'
str1=str1.replace('e','i')
print(str1)
str_exp()
Answer:
Covid – 19 forcis thi intiri worl to bi lockdown
All e replace with the letter i in the text.
3.
def str_exp():
str="Lockdown to Unlock 1.0"
d=str.split()
print(d)
str_exp()
Answer:
[‘Lockdown’, ‘to’, ‘Unlock’, ‘1.0’]
The words will be separated in a string after space
4.
import math
def mth_exp():
a=5.5
b=3.75
c=2.25
print(round(math.fsum([a,b,c]),0))
mth_exp()
Answer:
12.0
Function fsum() returns sum of specified variables a,b,c. The values are 5.5 + 3.75 + 2.25 = 11.5. Then round function returns next integer if
the adjecent digit is more than 5. So the final output will be 12.0
In the next section of important QnA python library functions 12 we will provide you some programs for QnA python library functions
12.
1. Write a program to accept the marks of 5 subjects and do the following:
1. Display the total using fsum() function
2. Display total marks in round integers
Ans.:
import math
def compute_result():
eng=float(input("Enter marks of English:"))
phy=float(input("Enter marks of Physics:"))
che=float(input("Enter marks of Chemistry:"))
mat=float(input("Enter marks of Maths:"))
cs=float(input("Enter marks of Computer Science:"))
tot=round(math.fsum([eng,phy,che,mat,cs]),0)
print("Total:",tot)
compute_result()
2. Write a program to display the computation of power using math module function.
Ans.:
import math
def compute_power():
no=int(input("Enter the number:"))
p=int(input("Enter the power to be raised:"))
ans=math.pow(no,p)
print("The",p,"power of ",no," is:", ans)
compute_power()
3. Write a program to convert the first letter of the sentence into a capital letter.
Ans.:
def first_upper():
s=input("Enter the sentences:(in lower case:)")
print(s.capitalize())
first_upper()
4. Write a program to convert the first letter of each word of the sentence into a capital letter.
def first_upper():
s=input("Enter the sentences:(in lower case:)")
print(s.title())
first_upper()
Important QnA Python Library Functions Class 12
Topics Covered
1. QnA Python Library Functions class 12
2. Theory Questions
3. Application Based questions
3.1. Error Based questions
3.2. Output Questions
Theory Questions
1. What is a library?
2. Write a few examples of commonly used libraries with examples.
3. What is the python module? Explain the structure of the python module.
4. How to import the python module?
5. Explain the commonly used python mathematical methods/functions with examples.
6. Explain the commonly used python string/text methods/functions with examples.
Follow this link to find the above answers of QnA Python Library Functions Class 12.
In the next section of QnA Python Library Functions class 12 we will discuss some application based questions.
1. def python_lib():
x = float(input(“Enter the number:”))
y = Math.ceil((x)
Assume that, x = 10.66777878
Ans.: There are three errors in the code, import math statement is missing and y = math.ceil(x) should be used.
2. x = 5
y = math.pow(3)
Ans.: There are two errors in the code, import math statement is missing and pow() function required two parameters,
3. a = 10
b = sqrt(a,2)
Assume that math module is imported.
4. s = “Welcome to My Blog”
print(str.s.capitalise())
Ans.: Error in print() function. The method capitalize() not written correctly and str word is not required.
Output Questions
Note: Assume that the math module is imported wherever required.
1. x = -45.2342343254325
b = math.fabs(x)
y = math.ceil(b)
print(y+5)
Ans.: 51
fabs() function convert the nagetive value into postive. As ceil() function returns the nearest integer of the passed argument value as well as
in print() function y+5 is written. So math.ceil(x) returns 46, 46 + 5 = 51.
2. import math
def python_lib():
s = “Computer Science with Python”
print(s.swapcase())
print(s.title())
print(s.split())
print(s.replace(‘with’,’-‘))
python_lib()
Ans.:
cOMPUTER sCIENCE WITH pYTHON
Computer Science With Python
[‘Computer’, ‘Science’, ‘with’, ‘Python’]
Computer Science – Python
3. import math
def python_lib():
s = “Python is midlle level language. Learning python is fun.”
c=0
w = s.split()
for i in w:
if i==’is’:
c=c+1
print(c)
python_lib()
Ans.: 2
In this code w = s.split() is used that generates a list of words from the text. Then in the for loop, if condition is given for counting the word
‘is’ is available 2 times in the text. Then finally the counter variable is printed. So the output is 2.
4. import math
def python_lib():
s = “Python is Programing Platform that Playful”
w = s.split()
c=0
for i in w:
if i[0]==’P’:
print(i,end=”#”)
python_lib()
Ans.: Python#Programing#Platform#Playful#
In for loop, i[0] is searching the word starts with letter P and printed in the next line.
5. import math
def python_lib():
s = “Python is Programing Platform that is Playful”
s1=”
print(s.lstrip(‘yPt’))
print(s.rstrip(‘Pul’))
print(s1.join([s,’ in 2020′]))
python_lib()
Ans.:
hon is Programing Platform that is Playful
Python is Programing Platform that is Playf
Python is Programing Platform that is Playful in 2020
Working with Functions XII – 13 Output & Error Questions with
easy solutions
Find the solved host questions for working with functions xii output
and error based questions.
Topics Covered
1. Working with functions xii Output Questions
2. Error-based questions
Error-based questions
1. def in(x,y):
x=x + y
print(x.y)
x*=y
print(x**y)
Ans.: def in(x,y): à in can’t be used as function name because it’s a keyword
print(x.y) à The variable in python print() function separate by comma not dot
The next questions is based on default argument for working with functions xii.
2. void get(x=10,y):
x=x+y
print(x,n,y)
Ans.: void get(x=10,y): à Default argument must be assign a value from right to left
print(x,n,y) à ‘n’ must be enclosed with quotes
3. // Program to compute result
def res():
eng = 56
math = 40
sci = 60
if eng<=35 || math<=35 ||
sci=35
print(‘Not Qualified’)
else:
print(“Qualified”)
Ans.: // Program to compute result à // is not used in python, it should be #
if eng<=35 || math<=35 || à || is not any operator in python, it should be or
sci=35 à It should written in above line or should be use in upper line
This question is based on positional argument for working with functions xii.
4. a=5, b=10
def swap(x,y):
x=a+b
y=x–y
x=x–y
swap(a)
swap(15,34)
swap(b)
swap(a,b)
Ans.: a=5, b=10 à In python variable should not assign in single line by comma
swap(a) à The positional arguments must be passed
swap(b) à Same as above
5. def cal_dis(qty,rate=50,dis_rate): #discount rate = 5%
bil_amt = (qty*rate)*dis_rate
print(bil_amt)
caldis(10)
cal_dis(10,50,0.05)
Ans.: def cal_dis(qty,rate=50,dis_rate=0.05): #discount rate = 5%
caldis(10) à Function call statement; cal_dis should be there
So here I have tried with the most common topics from working with functions xii with questions and answers.
For all the contents of computer science click on the below given link:
https://www.tutorialaicsip.com/cs-xii/computer-science-class-12-python/