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

Given the list below, answer the following question:

mylist = ["Europe", "Asia", "North America", "South America", "Africa", "Australia", 2009, 2140, 12.5, 6.25]

?What is the result of mylist[2]?


Options are :

  • North America (Correct)
  • IndexError
  • Asia
  • Africa

Answer :North America

Considering the dictionary below (showing the population of some of the Eastern European countries) answer the following question.??

ee_countries = {"Croatia": "4.09M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Serbia": "6.8M", "Estonia": "1.3M" }??

Which is the correct way of adding Moldova to the dictionary, having a population of 4.1M?


Options are :

  • ee_countries["Moldova"] == "4.1M"
  • ee_countries(“Moldova�?) = "4.1M"
  • ee_countries["Moldova"] = "4.1M" (Correct)
  • ee_countries{“Moldova�?} = "4.1M"

Answer :ee_countries["Moldova"] = "4.1M"

Given the set below

??set1 = {62, 100, 4001, 82, 550, 4001, 228, 82.0, 21}??

What is the result of set1.add(450)?


Options are :

  • TypeError and the element doesn’t get added to the set
  • {21, 62, 82, 100, 228, 450, 550, 4001} (Correct)
  • No error, element doesn’t get added to the set.
  • SyntaxError

Answer :{21, 62, 82, 100, 228, 450, 550, 4001}

Considering the following string referenced by the fact variable, please select the correct answer to the question below.

fact = "Values live until nothing references them. Python keeps track of how many references each value has, and automatically cleans up values that have none."

What is the string method that will turn all lowercase characters to uppercase and vice-versa?


Options are :

  • fact.capitalize()
  • fact.swapcase() (Correct)
  • fact.casefold()
  • fact.turncase()

Answer :fact.swapcase()

Considering the dictionary below (showing the population of some of the Eastern European countries), answer the following question.

ee_countries = {"Ukraine": "43.7M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Moldova": "4.1M", "Estonia": "1.3M"} What is the result of sorted(ee_countries.values())[-2] ?


Options are :

  • '6.9M' (Correct)
  • '43.7M'
  • SyntaxError
  • '9.6M'

Answer :'6.9M'

Given the tuple below, answer the following question.??

mytuple = (100, 250, 300, 250, 500, 650, 700, 500, 900)??

How would you find the location (index) of the first occurrence of 500 in mytuple???


Options are :

  • None of these
  • mytuple.find(500)
  • mytuple.count(500)
  • mytuple.index(500) (Correct)

Answer :mytuple.index(500)

Given the code below, answer the following question.

What is the length of set1?


Options are :

  • 8
  • 7 (Correct)
  • 6
  • 9

Answer :7

Which of the following are not valid ways of defining a set?


Options are :

  • list1 = [24,300,3000,78,400] set1 = set{list1} (Correct)
  • list1 = [24,300,3000,78,400] set1 = set(list1)
  • set1 = [24,300,3000,78,400]
  • list1 = [24,300,3000,78,400] set1 = set[list1] (Correct)

Answer :list1 = [24,300,3000,78,400] set1 = set{list1} list1 = [24,300,3000,78,400] set1 = set[list1]

Given the code below, answer the following question.

What is the result of d % 10?


Options are :

  • 10
  • 0 (Correct)
  • Syntax Error
  • 25

Answer :0

Considering the dictionary below (showing the population of some of the Eastern European countries) answer the following question.

??ee_countries = {"Croatia": "4.09M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Serbia": "6.8M", "Estonia": "1.3M" }??

Which is the correct way of deleting Estonia from the dictionary?


Options are :

  • ee_countries["Estonia"].truncate()
  • del ee_countries["Estonia"] (Correct)
  • ee_countries["Estonia"].remove()
  • ee_countries["Estonia"].delete()

Answer :del ee_countries["Estonia"]

You created the following program to locate a conference room and display room name.

Your team reported that the program sometimes produces incorrect results.

You need to troubleshoot the program. Why does Line-3 Fail to find the rooms?


Options are :

  • None of these
  • Misnamed variable(s)
  • Invalid Syntax (Correct)
  • The mismatched data type(s)

Answer :Invalid Syntax

Consider the following code:

Which of the following method calls are valid?


Options are :

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

Answer :f1('10','20') f1(10) f1()

We are developing a loan collection agent application. Consider the code:

What will be the value of the commission?


Options are :

  • 100
  • 150
  • 200
  • 350 (Correct)

Answer :350

Consider the code:

What is the result?


Options are :

  • 4
  • 2
  • 3
  • 1 (Correct)

Answer :1

Consider the following code:

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[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[0],numbers[-1] low,high=find_numbers() (Correct)
  • 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 following code:

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

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

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.

Which of the following is True about this code?


Options are :

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

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

You are developing an online shopping application.

What is the result?


Options are :

  • 85
  • 75 (Correct)
  • 65
  • 55

Answer :75

Consider the code:

What is the result?


Options are :

  • 2 (Correct)
  • 1
  • 4
  • 3

Answer :2

You want to add comments to your code so that other team members can understand it.

What should you do?


Options are :

  • Place the comments inside parentheses anywhere
  • Place the comments before the first line of code separated by a blank line
  • Place the comments after the last line of the code separated by a blank line
  • Place the comments after the #sign on any line (Correct)

Answer :Place the comments after the #sign on any line

We are developing one school automation application. If the student marks between 80 and 100, then we have to offer 'A' grade.

Which code block we have to use?


Options are :

  • if marks>80: grade='A'
  • if 80<=marks<=100: grade='A' (Correct)
  • if marks>=80 or marks<=100: grade='A'
  • if marks>=80 and marks>=100: grade='A'

Answer :if 80<=marks<=100: grade='A'

Consider the following code:

Which grade will be printed to the console?


Options are :

  • A
  • B
  • C (Correct)
  • D

Answer :C

Consider the code:

What is the result?


Options are :

  • 30
  • 32
  • 29
  • 31 (Correct)

Answer :31

You are coding a math utility by using python.

You are writing a function to compute roots

The function must meet the following requirements

Which of the following root function should be used?


Options are :

  • def root(a,b): if a>=0: answer=a**(1/b) elif a%2 != 0: answer="Result is an imaginary number" else: answer=-(-a)**(1/b) return answer
  • def root(a,b): if a>=0: answer=a**(1/b) if a%2 == 0: answer="Result is an imaginary number" else: answer=-(-a)**(1/b) return answer
  • def root(a,b): if a>=0: answer=a**(1/b) elif a%2 == 0: answer=-(-a)**(1/b) else: answer="Result is an imaginary number" return answer
  • def root(a,b): if a>=0: answer=a**(1/b) elif a%2 == 0: answer="Result is an imaginary number" else: answer=-(-a)**(1/b) return answer (Correct)

Answer :def root(a,b): if a>=0: answer=a**(1/b) elif a%2 == 0: answer="Result is an imaginary number" else: answer=-(-a)**(1/b) return answer

We are developing a gold loan application for the XYZ company.

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


Options are :

  • 50001 (Correct)
  • 100001
  • 50000
  • 150000
  • 100000

Answer :50001

The XYZ Book Company needs a way to determine the cost that a student will pay for renting a Book.

The Cost is dependent on the time of the Book is returned.

However, there are also special rates on Saturday and Sundays.

The Fee Structure is shown in the following list:

Below is the code to meet these requirements.

If the Book rented on 'Sunday', the number of days Book rented is 5 and Book returned after 9 PM then what is the result?


Options are :

  • The Cost of Book Rental is:$ 8.0
  • The Cost of Book Rental is:$ 10.0
  • The Cost of Book Rental is:$ 7.0
  • The Cost of Book Rental is:$ 9.0 (Correct)

Answer :The Cost of Book Rental is:$ 9.0

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:

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


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:{:.2f}'.format(average)) (Correct)
  • print('The average star rating for the new coffee is:{:2.2d}'.format(average))
  • print('The average star rating for the new coffee is:{:.2d}'.format(average))

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

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 a decimal point ( like YYY.Y).

Consider the code:

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


Options are :

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

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

We are creating a function to calculate the power of a number by using python.

We have to ensure that the function is documented with comments.

Consider the code(Line numbers included for reference):

Which of the following statements are true?


Options are :

  • The hash sign(#) is optional for lines 01 and 03.
  • Lines 01 through 04 will be ignored for syntax checking (Correct)
  • The String in line 06 will be interpreted as a comment

Answer :Lines 01 through 04 will be ignored for syntax checking

We are developing an application for leave approval in XYZ Company.

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


Options are :

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

Answer :days = 4 and cause='Official'

Given the list below, answer the following question:

mylist = ["Europe", "Asia", "North America", "South America", "Africa", "Australia", 2009, 2140, 12.5, 6.25] 


What is the result of len(mylist) * 25 / 5?


Options are :

  • 250.0
  • 50.0 (Correct)
  • 50
  • 250

Answer :50.0

Considering the dictionary below (showing the population of some of the Eastern European countries), answer the following question.??

ee_countries = {"Croatia": "4.09M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Serbia": "6.8M", "Estonia": "1.3M" }??

Which is the correct way of returning the population of Estonia (only the numerical part)??


Options are :

  • float(ee_countries['Estonia'][1:3])
  • float(ee_countries['Estonia'])
  • None of these
  • float(ee_countries['Estonia'].rstrip("M")) (Correct)

Answer :float(ee_countries['Estonia'].rstrip("M"))

Given the range below, answer the following question.

myrange = range(10, 28, 3) 

What is the result of list(myrange)[6]?


Options are :

  • 25
  • IndexError: list index out of range (Correct)
  • 28
  • 16

Answer :IndexError: list index out of range

Given the list below answer the following question.

list1 = ["Hello", "Hi", "Greetings", "Cheers", "Hi", "hello", "Greetings!"] What would be the correct result of set(list1) ?


Options are :

  • {'Cheers', 'Greetings', 'Hi', 'Greetings!', 'Hello', 'Hi', 'hello'}
  • {'Cheers', 'Greetings', 'Hello', 'Hi', 'hello'}
  • {'Cheers', 'Greetings', 'Greetings!', 'Hello', 'Hi', 'hello'} (Correct)
  • {'Cheers', 'Greetings', 'Greetings!', 'Hello', 'Hi'}

Answer :{'Cheers', 'Greetings', 'Greetings!', 'Hello', 'Hi', 'hello'}

Which of the following options will raise an IndexError exception?


Options are :

  • fact = "Python is in the top {0} programming language in the world" fact.format(10)
  • fact = "Python is in the top {0} programming language in the world" fact.format(5)
  • fact = "Python is in the top {1} programming language in the world" fact.format(5) (Correct)
  • fact = "Python is in the top {} programming language in the world" fact.format(5)

Answer :fact = "Python is in the top {1} programming language in the world" fact.format(5)

Considering the following string referenced by the fact variable, please select the correct answer to the question below. fact = "Python is the general-purpose language. Python is widely used in data analytics and machine learning.�?

What is the correct result of: "language" in fact.title()


Options are :

  • Error
  • FALSE (Correct)
  • TRUE

Answer :FALSE

Considering the dictionary below (showing the population of some of the Eastern European countries) answer the following question.??

ee_countries = {"Ukraine": "43.7M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Moldova": "4.1M", "Estonia": "1.3M"}

??What is the result of max(ee_countries.keys()) ?


Options are :

  • Russia’
  • �?143.8M’
  • �?Ukraine’ (Correct)
  • 143.8M

Answer :�?Ukraine’

Considering the dictionary below, answer the following question.

ee_countries = {"Ukraine": "43.7M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Moldova": "4.1M", "Estonia": "1.3M"}

?How can you create a copy of the ee_countries dictionary and save it using a new variable?


Options are :

  • new_dict = ee_countries.copy() (Correct)
  • new_dict = ee_countries.clone()
  • None of these
  • new_dict = ee_countries.duplicate()

Answer :new_dict = ee_countries.copy()

What is the result of: not(25 % 5 == 33 % 10) or (10 ** 4 > 3000)


Options are :

  • Exception at runtime
  • TRUE (Correct)
  • None
  • FALSE

Answer :TRUE

What is the correct way of defining a tuple having a single element?


Options are :

  • mytuple = ((70))
  • mytuple = (70,) (Correct)
  • mytuple = (70)
  • mytuple = {70,}

Answer :mytuple = (70,)

What is the result of the code below?

int('0011', 2)


Options are :

  • 4
  • 3 (Correct)
  • 2
  • 1

Answer :3

What does the items() method return when it is applied to a dictionary?


Options are :

  • TypeError
  • Returns a tuple of lists, where each list contains the key and value of each dictionary pair.
  • Returns a list of dictionaries, where each dictionary contains the key-value pair from the initial dictionary.
  • Returns a list of tuples, where each tuple contains the key and value of each dictionary pair. (Correct)

Answer :Returns a list of tuples, where each tuple contains the key and value of each dictionary pair.

What is the result of:

bool(0.0)


Options are :

  • TRUE
  • None
  • FALSE (Correct)
  • Exception at runtime

Answer :FALSE

Given the range below, answer the following question.??

myrange = range(5, 15) 

What is the result of tuple(myrange)?


Options are :

  • ValueError
  • (6, 7, 8, 9, 10, 11, 12, 13, 14)
  • (5, 6, 7, 8, 9, 10, 11, 12, 13, 14) (Correct)
  • (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)

Answer :(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)

Given the tuple below answer the following question.? mytuple = (100, 250, 300, 450, 500, "Python", "Java", "C++")??

What is the result of the below???

(mytuple + (410, 430, 450, 205 * 2, 900 // 2, 445)).count(450)


Options are :

  • 3 (Correct)
  • 2
  • 1
  • Syntax Error

Answer :3

What is the result of:


Options are :

  • 151.5
  • 153
  • 150 (Correct)
  • 152

Answer :150

Given the range below, answer the following question.??

myrange = range(11)[::2]??

What is the result of list(myrange)??


Options are :

  • [0, 2, 4, 6, 8, 10] (Correct)
  • [1, 3, 5, 7, 9, 11]
  • TypeError
  • [2, 4, 6, 8, 10]

Answer :[0, 2, 4, 6, 8, 10]

Which is not a valid option for removing a list element by its index?


Options are :

  • truncate() method
  • Del statement
  • remove() method (Correct)
  • pop() method

Answer :remove() method

Given the range below answer the following question.

myrange = range(3, 15, 2) 

What is the result of list(myrange)?


Options are :

  • [5, 7, 9, 11, 13]
  • [3, 5, 7, 9, 11, 13, 15]
  • [3, 5, 7, 9, 11, 13] (Correct)
  • [5, 7, 9, 11, 13, 15]

Answer :[3, 5, 7, 9, 11, 13]

Considering the following string referenced by the fact variable, please select the correct answer to the question below.

fact = "Python is the general-purpose language. Python is widely used in data analytics and machine learning"  What would be the result of fact.index("he") * fact.count("P") ?


Options are :

  • 44
  • 11
  • 33
  • 22 (Correct)

Answer :22

Given the list below, answer the following question:

mylist = ["Europe", "Asia", "North America", "South America", "Africa", "Australia", 2009, 2140, 12.5, 6.25]


Options are :

  • del mylist(-1)
  • del mylist([-1])
  • mylist.pop([-1])
  • mylist.pop(-1) (Correct)

Answer :mylist.pop(-1)

Considering the dictionary below (showing the population of some of the Eastern European countries), answer the following question.

?ee_countries = {"Croatia": "4.09M", "Russia": "143.8M", "Poland": "38.1M", "Romania": "19.5M", "Bulgaria": "6.9M", "Hungary": "9.6M", "Serbia": "6.8M", "Estonia": "1.3M" }??

What is the correct way of removing all the key-value pairs from the dictionary (result should be an empty dictionary)?


Options are :

  • ee_countries.clear() (Correct)
  • ee_countries.remove()
  • ee_countries.truncate()
  • ee_countries.delete

Answer :ee_countries.clear()

Given the string below, answer the following question.

fact = "Python is the general-purpose language. Python is widely used in data analytics and machine learning.�? 

How would you extract the �?language’ substring (excluding the surrounding white spaces) using positive indexes?


Options are :

  • fact[30:38] (Correct)
  • fact[31:37]
  • fact[29:36]
  • None of these

Answer :fact[30:38]

Given the sets below answer the following question.??

set1 = {26, 200, 2001, 92, 550}?set2 = {334, 92, 29, 650, 550, 25, 1002}??

Which of the following lines of code results in {26, 200, 2001}?


Options are :

  • set1.difference(set2) (Correct)
  • set1.intersection(set2)
  • set2.difference(set1)
  • set1.union(set2)

Answer :set1.difference(set2)

What is the result of the code below???


Options are :

  • "'1.3M', '143.8M', '19.5M', '38.1M', '4.1M', '43.7M', '6.9M', '9.6M'"
  • “('1.3M', '143.8M', '19.5M', '38.1M', '4.1M', '43.7M', '6.9M', �?9.6M')"
  • TypeError
  • "['1.3M', '143.8M', '19.5M', '38.1M', '4.1M', '43.7M', '6.9M', '9.6M']" (Correct)

Answer :"['1.3M', '143.8M', '19.5M', '38.1M', '4.1M', '43.7M', '6.9M', '9.6M']"

Given the range below, answer the following question.

??myrange = range(0, 10)??

What is the result of list(myrange)?


Options are :

  • [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  • [1, 2, 3, 4, 5, 6, 7, 8, 9]
  • [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] (Correct)
  • [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Answer :[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Given the list below, answer the following question:

mylist = ["Europe", "Asia", "North America", "South America", "Africa", "Australia", 2009, 2140, 12.5, 6.25] 

How would you skip every second element of mylist, so that you get this list: ['Europe', 'North America', 'Africa', 2009, 12.5]?


Options are :

  • mylist[:2:]
  • mylist[::2] (Correct)
  • mylist[::-2]
  • mylist[:2:4:6:8]

Answer :mylist[::2]

Given the tuple below answer the following question??

mytuple = (200, 350, 100, 150, 400, "Python", "Javascript", "C#")??

What is the result of mytuple[7:]?


Options are :

  • �?C#'
  • IndexError
  • ('Javascript', 'C#')
  • ('C#',) (Correct)

Answer :('C#',)

Given the string below, answer the following question. fact = "Python is the general-purpose language. Python is widely used in data analytics and machine learning." 

What is the result of fact[::-1]?


Options are :

  • Syntax Error
  • No change
  • Index Error
  • .gninrael enihcam dna scitylana atad ni desu ylediw si nohtyP .egaugnal esoprup lareneg eht si nohtyP' (Correct)

Answer :.gninrael enihcam dna scitylana atad ni desu ylediw si nohtyP .egaugnal esoprup lareneg eht si nohtyP'

What is the result of:


Options are :

  • (Correct)

Answer :

Consider the following expression

What is the result?


Options are :

  • 9
  • 7 (Correct)
  • 6
  • 8

Answer :7

Consider the Python code:

To print 'Valid' to the console, which condition we have to take for if statement?


Options are :

  • x > y (Correct)
  • x == y
  • x <= y
  • x < y

Answer :x > y

Which of the following expression will generate max value?


Options are :

  • 8//3*4
  • 8%3*4
  • 8/3*4 (Correct)
  • 8-3*4

Answer :8/3*4

Consider the following python code:

The types of weight, zip, and value variables respectively:


Options are :

  • int, str, float
  • float, str, str
  • float, str, float (Correct)
  • double, str, float

Answer :float, str, float

Which of the following code snippet will produce the output:


Options are :

  • l=['Apple','Boy','Cat','Dog'] for x in l: if len(x) == 3: print(x) (Correct)
  • 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) (Correct)

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)

Consider the lists:

What is the result?


Options are :

  • False True True True
  • False False True True (Correct)
  • False True False True
  • True False True False

Answer :False False True True

Consider the code

What is the result?


Options are :

  • ['A','B',' ','C','D','EF'] (Correct)
  • ('A','B',' ','C','D','EF')
  • {'A','B',' ','C','D','EF'}
  • ['A','B','C','D','EF']
  • ['A','B','C','D','E','F']

Answer :['A','B',' ','C','D','EF']

You have the following code:

What is the result?


Options are :

  • 11 (Correct)
  • 13
  • 10
  • 12

Answer :11

Consider the expression:

result=a-b*c+d

Which of the following are valid?


Options are :

  • First, b*c will be evaluated followed by addition and subtraction (Correct)
  • The above expression is equivalent to a-(b*c)+d (Correct)
  • First, a-b will be evaluated followed by multiplication and addition
  • First, b*c will be evaluated followed by subtraction and addition (Correct)

Answer :First, b*c will be evaluated followed by addition and subtraction The above expression is equivalent to a-(b*c)+d First, b*c will be evaluated followed by subtraction and addition

Consider the list:

list=['Apple','Banana','Carrot','Mango']

Which of the following are valid ways of accessing 'Mango':


Options are :

  • list[3] (Correct)
  • list[-1] (Correct)
  • list[4]
  • list[0]

Answer :list[3] list[-1]

Consider the code:

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


Options are :

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

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

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


Options are :

  • 3**1 (Correct)
  • 23%5 (Correct)
  • 13//4 (Correct)
  • 11/3

Answer :3**1 23%5 13//4

Which of the following is valid python operator precedence order?


Options are :

  • Parenthesis Exponents Unary Positive, Negative and Not Addition and Subtraction Multiplication and Division And
  • Exponents Parenthesis Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And
  • Parenthesis Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And (Correct)
  • Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And Parenthesis

Answer :Parenthesis Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And

You are writing a Python program. You required to handle data types properly. Consider the code segment:

Identify the types of a, b, and c?


Options are :

  • a is of int type, b, and c are invalid declarations
  • a is of int type, b is of int type, and c is of int type
  • a is of int type, b is of str type, and c is of int type
  • a is of int type, b is of str type, and c is of str type (Correct)

Answer :a is of int type, b is of str type, and c is of str type

Which variables represent True?


Options are :

  • c, d
  • a, b
  • All Variables
  • b, c (Correct)
  • d, a

Answer :b, c

Consider the code

To make 'a' value as 9, which expression required to place at Line-1?


Options are :

  • a **= 2 (Correct)
  • a *= 2
  • a -= 2
  • a += 2

Answer :a **= 2

Consider the code:

What is the result?


Options are :

  • 7.0
  • 5
  • 5.0 (Correct)
  • 6.0

Answer :5.0

Consider the following lists:

What is the output?


Options are :

  • True True
  • False True (Correct)
  • True False
  • False False

Answer :False True

You are writing a python program that evaluates an arithmetic expression.

The expression is described as b equals a multiplied by negative one, then raised to the second power, where a is the value which will be input and b is the result.

a = eval(input('Enter a number for the expression:'))

Which of the following is a valid expression for the given requirement?


Options are :

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

Answer :b = (-a)**2

You are writing a Python program to read two int values from the keyboard and print the sum.

Which of the following code we have to write at Line-1 to print the sum of given numbers?


Options are :

  • print('The Result:'+(int(x)+int(y)))
  • print('The Result:'+str(int(x)+int(y))) (Correct)
  • print('The Result:'+str(int(x+y)))
  • print('The Result:'+(int(x+y)))

Answer :print('The Result:'+str(int(x)+int(y)))

Consider the following code

For which of the following condition True will be printed to the console?


Options are :

  • x != y
  • x < y
  • x is not y
  • x is y (Correct)

Answer :x is y

Consider the following code segments:

# Code Segment-1

# Code Segment-2

# Code Segment-3

After executing Code Segments 1, 2, and 3 the result types of c1, c2, and c3 are: -


Options are :

  • c1 is of str type, c2 is of float type, c3 is of float type (Correct)
  • c1 is of str type, c2 is of str type, c3 is of str type
  • c1 is of str type, c2 is of int type, c3 is of int type
  • c1 is of str type, c2 is of int type, c3 is of float type

Answer :c1 is of str type, c2 is of float type, c3 is of float type

Suppose you are developing a python application for your company.

A list named employees contains 600 employee names, the last 3 being company management. You need to slice employees to display all employees excluding management. Which two code segments we should use?


Options are :

  • employees[1:-2]
  • employees[:-3] (Correct)
  • employees[0:-3] (Correct)
  • employees[1:-3]
  • employees[0:-2]

Answer :employees[:-3] employees[0:-3]

Consider the code

Which of the following expression results in -4?


Options are :

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

Answer :(a+b)//d-c

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 :

  • employees[0:501]
  • employees[-10:10]
  • None of these options (Correct)
  • employees[1:1000]

Answer :None of these options

Consider the following python code:

What are the types of age, minor, and name variables respectively:


Options are :

  • float, bool, str
  • int, bool, str (Correct)
  • int, bool, char
  • bool, bool, str

Answer :int, bool, str

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


Options are :

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

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

Consider the following expression

result=(2*(3+4)**2-(3**3)*3)

What is the result value?


Options are :

  • 18
  • 19
  • 17 (Correct)
  • 16

Answer :17

Consider the code:

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


Options are :

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

Answer :print(x[2]+y[1]+z[1])

Consider the code:

To print 2 as output, which code we have to insert at Line-1


Options are :

  • s2 = s1.lstrip()
  • s2 = s1.strip() (Correct)
  • s2 = s1.lrstrip()
  • s2 = s1.rstrip()

Answer :s2 = s1.strip()

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions