## Microsoft Python Certification Exam (98-381) Practice Tests Set 3

##### We are developing an online shopping application. Consider the code
1. d =input('Enter day of the week:')
2. discount_percentage = 3
3. if d== 'Monday':
4. discount_percentage+=5
5. elif d== 'Tuesday':
6. discount_percentage+=7
7. elif d== 'Saturday':
8. discount_percentage+=10
9. elif d== 'Sunday':
10. discount_percentage+=20
11. else:
12. discount_percentage+=2

To get 5 as discount_percentage, which of the following input should be provided end-user?

Options are :

• Monday
• Tuesday
• Thursday
• Saturday
• Sunday

##### We are developing a gold loan application for the XYZ company.
1. amount=float(input('Enter Loan Amount:'))
2. interest_rate=0
3. if amount > 0 and amount<= 50000:
4. interest_rate = 10
5. elif amount > 50000 and amount<100000:
6. interest_rate = 12
7. elif amount >= 100000 and amount<150000:
8. interest_rate = 16
9. else:
10. interest_rate = 22

For which of the following user input interest_rate will be 12.

Options are :

• 50000
• 50001
• 100000
• 100001
• 150000

##### We are developing an application for leave approval in XYZ Company.
1. days=int(input('Enter number of days for leave:'))
2. cause=input('Enter the cause:')
3. if days==1:
4. print('Leave will be approved immediately')
5. elif days>1 and days<=3:
6. if cause=='Sick':
7. print('Leave will be approved immediately')
8. else:
10. elif days>3 and days<5:
11. if cause=='Sick':
12. print('Needs Manager Approval')
13. else:
14. print('Needs Director Approval')
15. elif days>=5 and days<=10:
16. print('Needs Director Approval')

In which of the following cases, 'Needs Director Approval' will be printed to the console?

Options are :

• days = 2 and cause='Sick'
• days = 3 and cause='Personal'
• days = 4 and cause='Sick'
• days = 4 and cause='Official'

Answer :days = 4 and cause='Official'

##### Consider the following code:
1. marks=[30,40,50,45,50,100]
2. average=sum(marks)//len(marks)
4. if average>=90 and average<=100:
5. key=1
6. elif average>=80 and average<90:
7. key=2
8. elif average>=50 and average<80:
9. key=3
10. else:
11. key=4

Which grade will be printed to the console?

Options are :

• A
• B
• C
• D

##### Consider the code:
1. a=12
2. b=4
3. s='He shall not be happy if he does not work'

In which of the following cases result value will become 9

Options are :

• result=3 if None else a/b
• result=s.find('not') if s else None
• result=s.rfind('not') if s else None
• result=5 if len(s)>4 else 6

Answer :result=s.find('not') if s else None

##### We are developing loan collection agent application. Consider the code:
1. collected_amount=3000
2. commission=0
3. if collected_amount <= 2000:
4. commission=50
5. elif collected_amount> 2500 and collected_amount<3000:
6. commission=100
7. elif collected_amount>2500:
8. commission=150
9. if collected_amount>=3000:
10. commission+=200

What will be the value of commission?

Options are :

• 350
• 200
• 150
• 100

##### You are developing an online shopping application.
1. Consider the code:
2. order_value=1500
3. state='ap'
4. delivery_charge=0
5. if state in ['up','mp','ts']:
6. if order_value<=1000:
7. delivery_charge=50
8. elif order_value>1000 and order_value<2000:
9. delivery_charge=100
10. else:
11. delivery_charge=150
12. else:
13. delivery_charge=25
14. if state in ['lp','kp','ap']:
15. if order_value>1000:
16. delivery_charge+=20
17. if order_value<2000 and state in ['kp','ap']:
18. delivery_charge+=30
19. else:
20. delivery_charge+=15
21. print(delivery_charge)

What is the result?

Options are :

• 65
• 75
• 85
• 55

##### Consider the code:
1. l=[10,20,[30,40],[50,60]]
2. count=0
3. for i in range(len(l)):
4. if type(l[i])==list:
5. count=count+1
6. print(count)

What is the result?

Options are :

• 1
• 2
• 3
• 4

##### Consider the code:
1. l=[10,(20,),{30},{},{},[40,50]]
2. count=0
3. for i in range(len(l)):
4. if type(l[i])==list:
5. count+=1
6. elif type(l[i])==tuple:
7. count+=2
8. elif type(l[i])==set:
9. count+=3
10. elif type(l[i])==dict:
11. count+=4
12. else:
13. count+=5
14. print(count)

What is the result?

Options are :

• 17
• 18
• 19
• 20

##### Consider the code:
1. t = (2,4,6,8,10,12)
2. d = {1:'A',2:'B',3:'C',4:'D',5:'E',6:'F'}
3. result=1
4. for t1 in t:
5. if t1 in d:
6. result+=t1
7. print(result)

What is the result?

Options are :

• 12
• 13
• 19
• 6

##### Consider the code:
1. t = (2,4,6,8,10,12)
2. d = {1:'A',2:'B',3:'C',4:'D',5:'E',6:'F'}
3. result=1
4. for t1 in t:
5. if t1 in d:
6. continue
7. else:
8. result+=t1
9. print(result)

What is the result?

Options are :

• 29
• 30
• 31
• 32

##### Consider the code:
1. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
2. v = values[0][0]
3. for lst in values:
4. for element in lst:
5. if v > element:
6. v = element
7. print(v)

What is the result?

Options are :

• 3
• 2
• 1
• 4

##### Consider the code
1. def get_names():
2. names=['Sunny','Bunny','Chinny','Vinny','Pinny']
3. return names[2:]
4. def update_names(elements):
5. new_names=[]
6. for name in elements:
7. new_names.append(name[:3].upper())
8. return new_names
9. print(update_names(get_names()))

What is the result?

Options are :

• ['CHI', 'VIN', 'PIN']
• ['VIN', 'PIN']
• ['CH', 'VI', 'PI']
• ['SU', 'BU']

##### Consider the following code
1. def my_list(x):
2. lst.append(a)
3. return lst
4. my_list('chicken')
5. my_list('mutton')
6. print(my_list('fish'))
7. to print the following to the console
8. ['chicken','mutton','fish']

x should be replaced with

Options are :

• a,lst=[]
• a,lst=()
• a,lst={}
• a,lst=None

##### Consider the following code:
1. def f1(x=0,y=0):
2. return x+y

Which of the following method calls are valid?

Options are :

• f1()
• f1('10','20')
• f1(10)
• f1('10')

##### Consider the following code:
1. def f1(x=0,y=0):
2. return x*y

Which of the following method calls are valid?

Options are :

• f1()
• f1('10','20')
• f1(10)
• f1('10')

##### Consider the following code:
1. numbers=[100,20,10,70,50,60,40,30,90,80]
2. #Insert Code Here
3. print('The highest Number:{} and Least Number:{}'.format(high,low))

Which of the following code should be inserted to print Highest Number as 100 and Least Number as 10

Options are :

• def find_numbers(): numbers.sort() return numbers[0],numbers[-1] low,high=find_numbers()
• def find_numbers(): numbers.sort() return numbers[0],numbers[len(numbers)] low,high=find_numbers()
• def find_numbers(): numbers.sort() return numbers[0],numbers[-1] low=find_numbers() high=find_numbers()
• def find_numbers(): numbers.sort() return numbers[2],numbers[0] low,high=find_numbers()

Answer :def find_numbers(): numbers.sort() return numbers[0],numbers[-1] low,high=find_numbers()

##### Consider the code:
1. numbers=[100,20,10,70,50,60,40,30,90,80]
2. def find_numbers():
3. numbers.sort()
4. return numbers[0],numbers[-1]
5. low=find_numbers()
6. high=find_numbers()
7. #Line-1

To print 10 100 to the console which of the following code we have to take at Line-1

Options are :

• print(low,high)
• print(low[0],high[-1])
• print(low[-1],high[0])
• print(low[2],high[0])

##### Consider the code:
1. def calculate(amount=6,factor=3):
2. if amount>6:
3. return amount*factor
4. else:
5. return amount*factor*2

Which of the following function calls returns 30

Options are :

• calculate()
• calculate(10)
• calculate(5,2)
• calculate(1)

##### Consider the following code
1. def fib_seq(n):
2. if n==0:
3. return 0
4. elif n==1:
5. return 1
6. else:
7. return fib_seq(n-1)+fib_seq(n-2)
8. for i in range(7):
9. print(fib_seq(i),end=',')

What is the result?

Options are :

• 0,1,1,2,3,5,8,
• 0,1,2,4,8,16,32,
• 0,1,0,2,0,4,0,
• None of these

##### You are developing a Python application for online game.
1. You need to create a function that meets the following criteria:
2. The function is named update_score
3. The function receives the current score and a value.
4. The function adds the value to the current score.
5. The function returns the new score.

Which of the following is a valid function to fulfill this requirement?

Options are :

• update_score(score,value): new_score=score+value return new_score
• def update_score(score,value): new_score=score+value return new_score
• def update_score(score,value): new_score=score+value pass new_score
• def update_score(): new_score=score+value return new_score

Answer :def update_score(score,value): new_score=score+value return new_score

##### The XYZ company is creating a program that allows customers to log the number of miles biked.The program will send messages based on how many miles the customer logs. Consider the following python code:
1. Line-1:
3. return name
4. Line-2:
5. calories=miles*calories_per_mile
6. return calories
7. distance=int(input('How many miles did you bike this week:'))
8. burn_rate=50
9. biker=get_name()
10. calories_burned=calc_calories(distance,burn_rate)
11. print(biker,", You burned about",calories_burned," calories")

The lines Line-1 and Line-2 should be replaced with:

Options are :

• Line-1 should be replaced with def get_name():
• Line-1 should be replaced with def get_name(name):
• Line-1 should be replaced with def get_name(biker):
• Line-2 should be replaced with def calc_calories(miles,calories_per_mile):
• Line-2 should be replaced with def calc_calories(miles,burn_rate):
• Line-2 should be replaced with def calc_calories():

Answer :Line-1 should be replaced with def get_name(): Line-2 should be replaced with def calc_calories(miles,calories_per_mile):

##### We are developing a mathematical function to find area for the given circle. if r is the radius then area is : pi*r**2Which of the following is valid function for this requirement?

Options are :

• import math def find_area(r): return math.pi*math.fmod(r,2)
• import math def find_area(r): return math.pi*math.fabs(r)
• import math def find_area(r): return math.pi*math.pow(r,2)
• None of these

Answer :import math def find_area(r): return math.pi*math.pow(r,2)

##### Consider the python code:
1. import random
2. print(int(random.random()*5))

Which of the following is true?

Options are :

• It will print a random int value from 0 to 5
• It will print a random int value from 1 to 5
• It will print a random int value from 0 to 5
• It will print a random int value from 0 to 4
• It will print 5

Answer :It will print a random int value from 0 to 4

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions