0% found this document useful (0 votes)
28 views3 pages

Class Test 6 Questions With Answers

The document discusses various topics related to Python programming concepts like recursion, loops, conditional statements, functions etc. It provides definitions and examples for recursive functions, string slicing, range() function, local and global variables, GCD of two numbers, linear search, loop statements with else clause and flow of execution for while loop. It also lists the conditional branching statements in Python and purpose of pass statement.

Uploaded by

athirayanpericse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Class Test 6 Questions With Answers

The document discusses various topics related to Python programming concepts like recursion, loops, conditional statements, functions etc. It provides definitions and examples for recursive functions, string slicing, range() function, local and global variables, GCD of two numbers, linear search, loop statements with else clause and flow of execution for while loop. It also lists the conditional branching statements in Python and purpose of pass statement.

Uploaded by

athirayanpericse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Class test – 6

1 Define recursive function (Nov/Dec 2022)

The process in which a function calls itself directly or indirectly is called recursion and the
corresponding function is called as recursive function. Using recursive algorithm, certain problems
can be solved quite easily. Examples of such problems are Towers of Hanoi (TOH),
Inorder/Preorder/Postorder Tree Traversals, Depth First Search (DFS) of Graph, etc

2 Name the two types of iterative statements supported by Python. (Nov/Dec 2022)

For Statement
While statement
3 Define string slicing. Give an example(Nov/Dec 2020)

String Slices : A segment of a string is called string slice, selecting a slice is similar to selecting a
character.
Eg:>>> s ='Monty Python'
>>> print s[0:5] Monty
>>> print s[6:12] Python
4 Write a program to display a set of strings using range( ) function

5 Do loop Statements have else clause? When it will be executed? (Nov/Dec 2019)

Loop statements may have an else clause, it is executed when the loop terminates through
exhaustion of the list (with for) or when the condition becomes false (with while), but not when the
loop is terminated by a break statement.

6 Write a program to display a set strings using range ( ) function? (Nov/Dec 2019)

for i in range(len(a)):

print(i,a[i])

7 Present the flow of execution for a while statement. (Dec/Jan 2019)

The statements inside the while loop is executed only if the condition is evaluated to true.

Syntax:
While condition
statement
Example:
# Program to add natural numbers upto, sum = 1+2+3+...+10
n = 10
# initialize sum and counter
sum = 0
i=1
while i <= n:
sum = sum + i
i = i+1 # update counter
9 Comment with an example on the use of local and global variable with same identifier name
(Apr/May 2019)

The scope of a variable refers to the places that you can see or access a variable. If we define a
variable on the top of the script or module, the variable is called global variable. The variables that
are defined inside a class or function is called local variable.

10 Write a Python program to GCD of two number and print the results (Jan 2018)

11 Write a Python program to compute the power of a number and print the results (Jan 2018)

12 List out the conditional branching statement in Python (Nov/Dec 2022)

Sometimes there are more than two possibilities and we need more than two branches. One way to
express a computation like that is a chained conditional:

Eg:
if x < y:
print 'x is less than y'
elif x > y:
print 'x is greater than y'
else: print 'x and y are equal'
elif is an abbreviation of “else if.” Again, exactly one branch will be executed. There is no limit on
the number of elif statements. If there is an else clause, it has to be at the end, but there doesn’t
have to be one.

13 What is the purpose of pass statement? (Apr/May 2022)

Using a pass statement is an explicit way of telling the interpreter to do nothing. Example:def bar():
pass If the function bar() is called, it does absolutely nothing.

14 What is linear search ?(Apr/May 2022)


Part- B

1. Outline the loop, break and continue statement in Python with an example (Nov/Dec 2022)

2. Write a python program in linear search binary search and its details.

3. Write the python program to find the factorial of a given number without recursion and with
recursion (Jan 2018).

4. Python Strings are immutable. Justify with an example (Dec/Jan 2019)

5. Brief fruitful function, with example (Nov/Dec 2020)

6. Write a python program to generate all permutations of a string using built in function (Nov/Dec
2019)

You might also like