Question Bank Function
Question Bank Function
Question Bank Function
Question Bank – 2
Q1. Write a function which input person name as argument and print greeting message as:
Good Morning <person-name>
Q2. Write a function which accept a number as argument and return 0, if it is an even number else
return 1.
Use this function in main program to accept a range from user (from lower to upper number)
and print the even numbers between them.
Q3. What do you mean by Formal and Actual Parameters? Explain giving example.
Q4. Write definition of a function HowMany(ID, VALUE) to count and display number of times the
VALUE is present in the list ID.
For example, if the ID contains [115, 25, 65, 59, 74, 25, 110, 250] and the VALUE contains 25,
the function should print: 25 found 2 times.
Q5. Write definition of a method EvenSum(NUMBERS) to add those values in the list of NUMBERS,
which are odd.
Example, if NUMBERS contain [1, 2, 3, 4, 5, 6], the it should print 9.
Q6. Write a function myfunc() which accept two numbers as parameter and return the sum of
square of first number and square root of second number.
Example: if a=4, b=16, then myfunc(a,b) will return 20.
Q7. Write a function printDate() which accept day, month, and year as parameter and print in the
given format.
Example: if d=15, m=4, y=2024, then printDate(d,m,y) will print 15-APR-2024.
Question Bank – 3
Q1. What do you mean by default argument in a function? Explain giving example.
Q2. Explain the three types of functions depending on their return value with example.
Q3. Name the python library modules which need to be imported to invoke the following functions:
(i) floor() (ii) randint() (iii) plot() (iv) sin()
Q4. Write definition of a method ZeroEnding(SCORES) to add all those values in the list of SCORES,
which are ending with zero(0) and display the sum.
Example, if SCORES contain [200, 456, 300, 100, 234, 678], the sum should be displayed as 600.
Q5. Write definition of a method printPrime(NUMBERS) to print prime numbers of the list of
NUMBERS. Example, if NUMBERS contain [1, 2, 3, 4, 5], the it should print 2, 3, 5.
Q6. Differentiate direct and indirect recursion with an example.
Q7. Write a function isPrime(N) which input a number as argument and return 0, if the number is
Prime else 1. Code another function isPalin(N) which input a number and return 0, if the
number is Palindrome else 1.
Now in main-program accept lower and upper range from user to print palprime numbers
between them. A palprime is a number which is both – palindrome and prime as well.
Example: Entre lower limit :100
Entre upper limit :150
The palprimes are :101 131
Question Bank – 4
Q1. Write a function findGrade(marks), which accept marks as argument and return the grade as
per given criteria:
Marks 90-100 75-90 60-75 45-60 33-45 <33
Grade A B C D E F
Now in main-program, accept marks of 40 students in a subject of your class and predict the
number of students in each grade.
Q2. Generate twin prime numbers between 1 and 100. Twin prime numbers are the two numbers
whose difference is 2 and both are prime numbers. Like (3,5), (11,13) etc.
Q3. Write the function which print as:
If display1() prints ‘*’ six times
If display2(int n) prints ‘#’ n times
If display3(int n, char ch) prints ch for n times
Call these functions in main-program and see the output.
Q4. Write a function findDistance(), which accept two points as arguments and return distance
between them.
Use the function in main-program to get the distance between (0,3) and(0,10).
Hint: p1=(0,3)
p2=(0,10)
d=findDistance(p1,p2)
print('The distance between',p1,'and',p2,'is',d)
Q5. Write a function findVowel(), which accept a message as argument and return the number of
vowels in it. Test the same function in main-program.
Hint: Original message is : This is a pen Output: The numbers of vowels are 4
Question Bank – 5
Q1. The following function is created for you:
def findInterest(principal, rate=5, time=2):
interest=(principal * rate * time)/100.0
return interest
then, find the output of the following code:
(a) print(findInterest(1000, 10, 5)) (b) print(findInterest(2000, 3))
(c) print(findInterest(5000)) (d) print(findInterest())
Q2. Write a function midPoint() which accept two points of 2-D and return the midpoint of them.
For example mid-point of (2, 4) and (6, 6) is (4, 5). Use the function in main-program to test
your Python code on the above values.
Q3. Write two forms of import statement.
Q4. Write a function myfunction(), which accept a list as argument and returns the index number
of highest element of the list. Example – suppose the list is L=[9, -45, 457, 85, 99], then if we
call myfucntion(L), it must return 2, which is index number of highest element of the list.
Q5. Write a function countMe(), which accept a message and a letter as argument and returns the
frequency of the letter in the message. For example – if the message is “This is KV Bharatpur”
and the letter is ‘i', then it must return 2 i.e. frequency of ‘i' in the message.
Use the above example in main-program to test your function.
Q6. What is the difference between Actual Parameter and Formal Parameter? Explain giving
example.
Q7. Write a function myfunction(), which accept a number as argument and prints number and its
square upto 1 in reverse order.
For example, if we call the function in main-program as
Myfunction(5), then output will be:
Number Square
5 25
4 16
3 9
2 4
1 1
Question Bank – 6
Q1. Write a function which accept a list and multiply its all elements and returns it. If any number
is zero, then it leaves that zero. Example if the list is L=[1,2,3,5,0,-6,4,5], the it returns -3600.
Write main function to test the sample list.
Q2. Write a python program that accepts hyphen-separated sequence of words as input and prints
the words in a hyphen-separated sequence after sorting them alphabetically.
Sample input string: vikash-vipin-ayush-navneet-shivanshu-abhishek
Expected output: abhishek-ayush-navneet-shivanshu-vikash-vipin-
Q3. Consider below given function headers. Identify which of these will cause error and why?
(i) def func (a = 1, b):
(ii) def func (a = 1, b, c = 2):
(iii) def func (a = 1, b = 2, c = 3):
Q4. Find and write the output of the following Python code:
data=["P",20,"R",10,"S",30]
times=0
alpha=""
add=0
for c in range(1,6,2):
times = times + c
alpha = alpha + data [c-1] + "$"
add = add + data[c]
print (times, add, alpha)