0% found this document useful (2 votes)
2K views

Selection Control

The document contains 10 multiple choice questions related to selection control structures in Python. The questions cover if-else statements, logical operators, nested if-else statements, and determining the most efficient test data to achieve logic coverage for given code snippets.

Uploaded by

Pavan Pulicherla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (2 votes)
2K views

Selection Control

The document contains 10 multiple choice questions related to selection control structures in Python. The questions cover if-else statements, logical operators, nested if-else statements, and determining the most efficient test data to achieve logic coverage for given code snippets.

Uploaded by

Pavan Pulicherla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Selection control structures

1.What is the output of the below code snippet?

num1=100

num2=200

num3=6

if(5>=num3):

if(num1>100 or num2>150):

print ("1")

elif(numl>=100 and num2>150):

print("2")

else:

print ("3")

A.1

B.2

C.3

2.What should be the value of num1 and num2 to get the output as "1"?

if((num1/num2==5) and (num1+num2) >5):

print("1")

elif((num1-num2)<=1 or (num1%num2)==0):

print("2")

else:

print ("3")

A.num1=11, num2=2

B.num1=0, num2=5

C.num1=5, num2=1
D.num1=-10,num2=2

3.Which among the following codes have equal logic?

Code 1:

if(value3>1000 and value3<1006):

if(value1=="ABC"):

if(value2=="A"):

value4=10

else:

value4=8

elif(value1=="XYZ"):

if(value2=="A"):

value4=8

else:

value4=6

print(value4)

Code 2:

if(value3>31001 and value3<31005 and value1=="ABC"):

if(value2=="A"):

value4=10

else:

value4=8

elif(value3>1000 and value<1006 and value1=="XYZ"):

if(value2=="A"):

value4=8

else:
value4=6

print(value4)

Code 3:

if(value3>1000 and value3<1006 or value1=="ABC"):

if(value2=="A"):

value4=10

else:

value4=8

elif(value3>1000 and value3<1006 or value1=="XYZ")=

if(value2=="A"):

value4=8

else:

value4=6

print(value4)

A. Code1& 2

B. Code 2&3

C. Code3&1

D. None

4.What is the output of the code given below?

a = -10

b = -200

C=2000

d = 4000

if( a*b >=d):


if(d>c):

if(d%c!=0):

print(11)

else:

print(22)

else:

if(b/a >0):

if(a<b or d%c!=0):

print(33)

else:

print(44)

1.11

2.22

3.44

4.33

5.Consider the below code snippet.


Identify the most efficient test data set for testing the below code using the ‘Logic Coverage’
technique.
if previous_year_percentage>=75 and previous_year_percentage<=85:
scholarship=5000
elif previous_year_percentage>85 and previous_year_percentage<=95:
scholarship=8000
elif previous_year_percentage>95:
scholarship=1000

else:
scholarship=0
A. 79, 87, 91, 99
B. 78, 80, 92, 99
C. 74, 77, 90, 100
D. 74, 75, 76, 84, 85, 86, 94, 95, 96, 97
6.What will be the output of the following Python code snippet?
def func (var1, var2, var3):
if(var1<=var2):
if(var3>-var2):
if(var1+var2>-var3):
print(-1)
else:
print(-2)
else:
if(var1+var3>var2):
print (-3)
else:
print (-4)
func(156,2100,9500)

A. -2
B. -3
C. -4

D. -1

7. Consider the following snipet?

def binary_search(num_list, element):

low=0

high=len(num_list)-1-

mid=(low+high)//2

while(num_list[mid]!=element and low<high):

if(element>num_list[mid]):-

low=mid+1

else:

high=mid-1

mid=(low+high)//2

if(element == num_list[mid]):
print Element is in the list at index", mid)

else:

print(Element is not in the list")

1.Change the code at line number 4 and 10 as mid=int(low+high)/2):

2.change the code at line number 6 as if(num_list[mid]==element):

3.Change the code at line number 6 as if(element< num_list[mid]):

4.Changethe code at line number 6 as if(element>=num_list[mid]):

8.Consider the code given below.

Identify the most efficient test data set for testing the below code using Logic Coverage' technique.

if item type-"Fashion":

if amount>500 and amount<-1000:

amount-amount-0.1* amount

elif item type"Electronics":

if amount>10000 and amount< 15000:

amount-amount-0.15*amount

else:

if amount>2000:

amount-amount-0.07*amount

print ("Final amount", amount)

A. item type: "Fashion" with amount as 100, "Electronics" with amount as 2001

B. item type: "Fashion" with amount as 700, "Electronics" with amount as 7000, Sports" with amount as-
1500
C. item type: "Fashion" with amount as 800, "Electronics" with amount as 14999, "Sports" with amount
as 2300

D. Item type: "Fashion" with amount as 760, "Electronics" with amount as 5030, "Lifestyle" with amount
as 230

9.Consider the following Python code that depicts BINARY SEARCH algorithm for the list of elements
sorted in ASCENDING ORDER

def binary_search(num_1ist, element):-

low=0

high=len(num_list)-1

mid3(low+high)//2

while(num list[mid]!=element and low<high):

if(element>num_list[mid]):

low=mid+1

else:

high=mid-1

mid%=(low+high)//2

if(element == num_list[mid]):

printnt("Element is in the list at index",mid)

else:

print("Element is not in the list")

Consider the list of numbers given below.

3,6,7,9,15,20

How many iterations wii be required to search the number 17?

A. 3

B. 4

C. 2
D. 5

10.Consider the below code written by Peter. He wants to test his code using "Logic Coverage"
technique.

Suggest him the most efficient test data set.

motorcycle type ="Bike"

years old =6

if (motorcycle_type =="Bike") :

if years_old >= 5 and years old <= 10):

mileage=45

elif years old >= 11:

mileage=40

else:

mileage= 25

elif (motorcycle_type = "Scooter"):

mileage=35

else:

mileage=20

A. motorcycle_type:"Bike" with years_old:(4, 8, -1), "Scooter", "Bus"

B.Motorcycle_type "Bike", "Scooter", "Bus"

C.Motorcycle_type "Bike" with years_old:(6, 9, 100), "Scooter", "Bus"

D. Motorcycle_type "Bike" with years_old:(2, 7, 15), "Scooter", "Bus"

You might also like