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

##### Consider the following variable declarations:
1. a= bool([])
2. b= bool(())
3. c= bool(range(0))
4. d= bool({})
5. e= bool(set())

Which of the above variables represent True ?

Options are :

• None of the variables represents True
• a ,b, c, d
• All Variables represent True
• c

Answer :None of the variables represents True

Options are :

• 8/3*4
• 8%3*4
• 8-3*4
• 8//3*4

##### Consider the code:
1. s='Python is easy'
2. s1=s[-7:]
3. s2=s[-4:]
4. print(s1+s2)

What is the result?

Options are :

• iseasyeasy
• easyeasy
• is easy easy
• s easyeasy
• is easyeasy

##### Consider the python code
1. numbers=[10,20,30,40]
2. x=0

In which of the following cases 10 will be printed to the console?

Options are :

• for i in (30,40,50): if i not in numbers: x=x+10 print(x)
• for i in (30,40,50): if i not in numbers: x=x+5 print(x)
• for i in (30,40,50): if i in numbers: x=x+5 print(x)
• for i in (30,40,50): if i in numbers: x=x+10 print(x)

Answer :for i in (30,40,50): if i not in numbers: x=x+10 print(x) for i in (30,40,50): if i in numbers: x=x+5 print(x)

Options are :

• 12
• 13
• 11
• 10

##### Consider the code:
1. start=input('How old were you at the time of joining?')
2. end=input('How old are you today?')

Which of the following code is valid to print Congratulations message?

Options are :

• print('Congratulations on '+ str(end-start)+' Years of Service!')
• print('Congratulations on '+ (int(end)-int(start))+' Years of Service!')
• print('Congratulations on '+ int(end-start)+' Years of Service!')
• print('Congratulations on '+ str(int(end)-int(start))+' Years of Service!')

Answer :print('Congratulations on '+ str(int(end)-int(start))+' Years of Service!')

1. a=bool(0)
2. b=bool(3)
3. c=bool(0.5)
4. d=bool(0.0)

Which variables represent True?

Options are :

• d, a
• All Variables
• a,b
• c,d
• b,c

Options are :

• b = -(a)**2
• b = (a-)**2
• b = (a)**-2
• b = (-a)**2

##### You are developing a python application for your company.A list named employees contains 500 employee names. In which cases we will get IndexError while accessing employee data?

Options are :

• None of the above
• employees[0:501]
• employees[1:1000]
• employees[-10:10]

##### Consider the following python code:
1. age=0
2. minor=False
3. name='test'

The types of age, minor and name variables, respectively:

Options are :

• int, bool, char
• float, bool, str
• int, bool, str
• bool, bool, str

##### Consider the lists:
1. numbers=[10,20,30,40,50]
2. alphabets=['a','b','c','d','e']
3. print( numbers is alphabets)
4. print( numbers == alphabets)
5. numbers=alphabets
6. print( numbers is alphabets)
7. print( numbers == alphabets)

What is the result?

Options are :

• True False True False
• False False True True
• False True True True
• False True False True

Options are :

• 3 3 3
• 3.5 3 3
• 3.5 3.5 3
• 3.0 3 3

##### Consider the code
1. a=1
2. b=2
3. c=4
4. d=6

Which of the following expression results in -4?

Options are :

• (b+c)//a%d
• (a+b)//c*d
• (a+b)//c%d
• (a+b)//d-c

##### In which of the following cases we will get same result

Options are :

• 11/3
• 23%5
• 13//4
• 3**1

1. subjects=['java','python','sap']
2. more_subjects=['java','python','sap']
3. extra_subjects=more_subjects

In which cases, True will be printed to the console?

Options are :

• print(subjects == extra_subjects)
• print(subjects is extra_subjects)
• print(extra_subjects is more_subjects)
• print(subjects is more_subjects)

Answer :print(subjects == extra_subjects) print(extra_subjects is more_subjects)

##### Which of the following code snippet will produce the output:
1. Boy
2. Cat
3. Dog

Options are :

• l=['Apple','Boy','Cat','Dog'] for x in l: if len(x) == 3: print(x)
• l=['Apple','Boy','Cat','Dog'] for x in l: print(x)
• l=['Apple','Boy','Cat','Dog'] l1=l[1:] for x in l1: print(x)
• l=['Apple','Boy','Cat','Dog'] for x in l: if len(x) != 3: print(x)

Answer :l=['Apple','Boy','Cat','Dog'] for x in l: if len(x) == 3: print(x) l=['Apple','Boy','Cat','Dog'] l1=l[1:] for x in l1: print(x)

##### You are developing a python application for your company.A list named employees contains 500 employee names,the last 3 being company management. Which of the following represents only management employees.

Options are :

• employees[-3:]
• employees[497:500]
• employees[497:]
• All the above

##### Consider the code:
1. x='ACROTE'
2. y='APPLE'
3. z='TOMATO'

Which of the following won't print 'CAT' to the console

Options are :

• print(x+y+z)
• print(x[-5]+y+z)
• print(x[-5]+y+z[-2])
• print(x+y+z)

Options are :

• 16
• 18
• 19
• 17

##### The XYZ organics company needs a simple program that their call center will use to enter survey data for a new coffee variety. The program must accept input and return the average rating based on a five-star scale. The output must be rounded to two decimal places. Consider the code:
1. sum=count=done=0
2. average=0.0
3. while(done != -1):
4. rating=float(input('Enter Next Rating(1-5),-1 for done'))
5. if rating == -1:
6. break
7. sum+=rating
8. count+=1
9. average=float(sum/count)
10. #Line-1

Which of the following print() statement should be placed at Line-1 to meet requirement?

Options are :

• print('The average star rating for the new coffee is:{:.2f}'.format(average))
• print('The average star rating for the new coffee is:{:.2d}'.format(average))
• print('The average star rating for the new coffee is:{:2f}'.format(average))
• print('The average star rating for the new coffee is:{:2.2d}'.format(average))

Answer :print('The average star rating for the new coffee is:{:.2f}'.format(average))

##### Consider the following statements:
1. 1. print('V:{:.2f}'.format(123.45678)) will print to the console V:123.46
2. 2. print('V:{:.2f}'.format(123.4)) will print to the console V:123.40
3. 3. print('V:{:8.2f}'.format(1.45678)) will print to the console V: 1.46
4. 4. print('V:{:08.2f}'.format(1.45678)) will print to the console V:00001.46

Which of the above statements are True?

Options are :

• only 1 and 2
• only 1 and 3
• only 2 and 4
• 1,2,3 and 4

##### We are developing a sports application. Our program should allow players to enter their names and score. The program will print player name and his average score. Output must meet the following requirements:The user name must be left-aligned. If the user name is fewer than 20 characters, additional space must be added to the right. The average score must be 3 places to the left of the decimal point and one place to the right of the decimal point ( like YYY.Y). Consider the code:
2. score=0
3. count=0
4. sum=0
5. while(score != -1):
6. score=int(input('Enter your scores: (-1 to end)'))
7. if score==-1:
8. break
9. sum+=score
10. count+=1
11. average_score=sum/count
12. #Line-1

Which print statement we have to take at Line-1 to meet requirements.

Options are :

• print('%-20s,Your average score is: %4.1f' %(name,average_score))
• print('%-20f,Your average score is: %4.1f' %(name,average_score))
• print('%-20s,Your average score is: %1.4f' %(name,average_score))
• print('%-20s,Your average score is: %4.1s' %(name,average_score))

##### Consider the following code:
1. numbers=[0,1,2,3,4,5,6,7,8,9]
2. index=0
3. while (index<10)#Line-1
4. print(numbers[index])
5. if numbers(index) = 6#Line-2
6. break
7. else:
8. index += 1

To print 0 to 6,which changes we have to perform in the above code?

Options are :

• Line-1 should be replaced with while(index<10):
• Line-2 should be replaced with if numbers[index]==6:
• Line-2 should be replaced with if numbers[index]=6:
• Line-1 should be replaced with while(index>0):

Answer :Line-1 should be replaced with while(index<10): Line-2 should be replaced with if numbers[index]==6:

##### You are writing a Python program to validate employee numbers. The employee number must have the format dd-ddd-dddd and consists of only numbers and dashes. The program must print True if the format is correct, otherwise print False.
2. parts=employee_number.split('-')
3. valid=False
4. if len(parts) == 3:
5. if len(parts)==2 and len(parts)==3 and len(parts)==4:
6. if parts.isdigit() and parts.isdigit() and parts.isdigit():
7. valid=True
8. print(valid)

Options are :

• It will throw an error because of the misuse of split() method
• It will throw an error because of the misuse of isDigit() method
• There is no error, but it won't fulfill our requirements.
• No changes are required for this code, and it can fulfill the requirement.

Answer :No changes are required for this code, and it can fulfill the requirement.

##### You are coding a math utility by using python.
1. You are writing a function to compute roots
2. The function must meet the following requirements
3. If a is non-negative, return a**(1/b)
4. If a is negative and even, return "Result is an imaginary number"
5. if a is negative and odd,return -(-a)**(1/b)

Which of the following root function should be used?

Options are :

##### You are writing an application that uses the sqrt function. The program must reference the function using the name sq. Which of the following import statement required to use?

Options are :

• import math.sqrt as sq
• import sqrt from math as sq
• from math import sqrt as sq
• from math.sqrt as sq

Answer :from math import sqrt as sq

##### Consider the code:
1. import math
2. l =[str(round(math.pi)) for i in range (1, 6)]
3. print(l)

What is the result?

Options are :

• ['3', '3', '3', '3', '3']
• ['3', '3', '3', '3', '3','3']
• ['1', '2', '3', '4', '5']
• ['1', '2', '3', '4', '5','6']

Answer :['3', '3', '3', '3', '3']

##### You are writing code that generates a random integer with a minimum value of 5 and maximum value of 11. Which of the following 2 functions we required to use?

Options are :

• random.randint(5,12)
• random.randint(5,11)
• random.randrange(5,12,1)
• random.randrange(5,11,1)

##### Consider the following code:
1. import random
2. fruits=['Apple','Mango','Orange','Lemon']

Which of the following will print some random value from the list?

Options are :

• print(random.sample(fruits))
• print(random.sample(fruits,3))
• print(random.choice(fruits))
• print(random.choice(fruits))

##### We are developing an application for the client requirement.As the part of that we have to create a list of 7 random integers between 1 and 7 inclusive.Which of the following code should be used?

Options are :

• import random randints=[random.randint(1,7) for i in range(1,8)]
• import random randints=[random.randint(1,8) for i in range(1,8)]
• import random randints=random.randrange(1,7)
• import random randints=random.randint(1,7)

Answer :import random randints=[random.randint(1,7) for i in range(1,8)]

##### Consider the code:
1. import random
2. fruits=['Apple','Mango','Orange','Lemon']
3. random_list=[random.choice(fruits)[:2] for i in range(3)]
4. print(''.join(random_list))

Which of the following are possible outputs?

Options are :

• ApApAp
• ApMaOr
• LeMaOr
• OrOraM