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

Consider the following code:
  1. v1 = 1
  2. v2 = 0
  3. v1 = v1 ^ v2
  4. v2 = v1 ^ v2
  5. v1 = v1 ^ v2
  6. print(v1)

What is the result?

Options are :

  • 0
  • 3
  • 2
  • 1

Answer :0

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


Options are :

  • print('r' in 'Larry')
  • print('is' in 'This IS a Fake News')
  • a=45 b=45 print(a is not b)
  • x=[1,2,3] y=[1,2,3] print(x is y)
  • s1='The Python Course' s2='The Python Course'.upper() print(s1 is s2)

Answer :print('r' in 'Larry') print('is' in 'This IS a Fake News')

Consider the code
  1. x='10'
  2. y='20'

The type of x+y ?

Options are :

  • int
  • complex
  • str
  • float

Answer :str

Consider the code
  1. a=7
  2. b=3
  3. c=5
  4. d=1

Which line of the code assigns 9 to the output?

Options are :

  • output=a%c+1
  • output=a+d*2
  • output=c*d-1
  • output=a+c//d

Answer :output=a+d*2

Consider the code:
  1. from sys import argv
  2. print(argv[0])

and given the command invocation:py test.py SampleTextWhat is the result?

Options are :

  • ImportError will be thrown at runtime
  • test.py
  • IndexError will be thrown at runtime
  • SampleText

Answer :test.py

Given the command invocation:py test.py AlexWhich of the following code prints 'Alex' to the console?


Options are :

  • from sys import argv print(argv[0])
  • from sys import args print(args[1])
  • from sys import argv print(argv[1])
  • from sys import args print(args[0])

Answer :from sys import argv print(argv[1])

Consider the codea=float('123.456')Which expression evaluates to 2?


Options are :

  • int(a)+False
  • str(a)
  • bool(a)
  • bool(a)+True

Answer :bool(a)+True

Consider the following code:print(type(input('Enter some value:')))if we enter 10 and 10.0 individually for every run what is the output?


Options are :

Answer :

Consider the code:
  1. print(not 0)
  2. print(not 10)
  3. print(not '')
  4. print(not 'Google')
  5. print(not None)

What is the result?

Options are :

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

Answer :True False True False True

You develop a Python application for your company. You required to accept input from the user and print that information to the user screen. Consider the code:
  1. print('Enter Your Name:')
  2. #Line-1
  3. print(name)

At Line-1, which code we have to write?

Options are :

  • input(name)
  • name=input()
  • name=input
  • input('name')

Answer :name=input()

You are intern for XYZ Cars Company.You have to create a function that calculates the average velocity of vehicle on a 2640 foot(1/2 mile)track.Consider the python code
  1. distance=xxx(input('Enter the distance travelled in feet:')) #Line-1
  2. distance_miles=distance/5280
  3. time=yyy(input('Enter the time elapsed in seconds:')) #Line-2
  4. time_hours=time/3600
  5. velocity=distance_miles/time_hours
  6. print('The average Velocity:',velocity,'miles/hour')

To generate most precise output, which modifications should be done at Line-1 and at Line-2.

Options are :

  • xxx should be replaced with int and yyy should be replaced with int
  • xxx should be replaced with int and yyy should be replaced with float
  • xxx should be replaced with float and yyy should be replaced with int
  • xxx should be replaced with float and yyy should be replaced with float

Answer :xxx should be replaced with float and yyy should be replaced with float

Consider the code
  1. count=input('Enter the number of customers of the bank:')
  2. #Line-1
  3. print(output)

Which code inserted at Line-1 will print 20 to the console if we pass 15 as count value from the console?

Options are :

  • output=str(count)+5
  • output=int(count)+5
  • output=float(count)+5
  • output=count+5

Answer :output=int(count)+5

Consider the variable declarationb = 'BANANA'Which of the following lines will print 'AA' to the console?


Options are :

  • print(b[1]+b[3])
  • print(b[1]+b[5])
  • print(b[1]+b[2])
  • print(b[3]+b[5])

Answer :print(b[1]+b[3]) print(b[1]+b[5]) print(b[3]+b[5])

Which of the following are valid statements?


Options are :

  • type('') is
  • True and False evaluates to False
  • True or False evaluates to False
  • True+1 evaluates to 2
  • 5+False evaluates to False

Answer :True and False evaluates to False True+1 evaluates to 2

Consider the following expression:6//4%5+2**3-2//3This expression results in:


Options are :

  • -1
  • 25
  • 3
  • 9

Answer :9

Consider the Variable declarations:
  1. a='5'
  2. b='2'

Which of the following expressions are of type str

Options are :

  • a-b
  • a*b
  • a*2
  • a+b

Answer :a*2 a+b

Consider the code
  1. x=3
  2. x +=1
  3. #Line-1

Which line should be inserted at Line-1 so that x value will become 16?

Options are :

  • x**=2
  • x*=2
  • x+=2
  • x-=2

Answer :x**=2

Consider the codet=([10,20],10,False)Which line of the code assigns <class 'list'> to x


Options are :

  • x= type(t[0:])
  • x= type(t)
  • x= type(t[0])
  • x= type(t[1])

Answer :x= type(t[0])

Which expression evaluates to 4?


Options are :

  • 7/2*3
  • 7%2+3
  • 7//2-3
  • 7-2*3

Answer :7%2+3

Consider the Code
  1. x=3/3+3**3-3
  2. print(x)

What is the output?

Options are :

  • 0.11
  • 25
  • 25.0
  • 32

Answer :25.0

In which of the following cases we will get <class 'int'> as output?


Options are :

  • x=47.0 print(type(x))
  • x=2**2**2 print(type(x))
  • x=10+20j print(type(x))
  • x='47' print(type(x))

Answer :x=2**2**2 print(type(x))

The XYZ Company has hired you as an intern on the coding team that creates a e-commerce application.You must write a script that asks the user for a value. The value must be used as a whole number in a calculation,even if the user enters a decimal value.Which of the following meets this requirement?


Options are :

  • total_items=float(input('How many items you required?'))
  • total_items=str(input('How many items you required?'))
  • total_items=int(float(input('How many items you required?')))
  • total_items=input('How many items you required?')

Answer :total_items=int(float(input('How many items you required?')))

Consider the Python code:
  1. l1=['sunny','bunny','chinny','vinny']
  2. l2=['sunny','bunny','chinny','vinny']
  3. print(l1 is not l2)
  4. print(l1 != l2)
  5. l1=l2
  6. print(l1 is not l2)
  7. print(l1 != l2)

What is the result?

Options are :

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

Answer :True False False False

Which of the following statements are valid?


Options are :

  • The following expression evaluates to 12 b=False+5-True+35//4
  • The following line will print result:4.5 print('result:',(7/2)+(False or True)+(9%3))
  • result=456+456.0 type of result is int
  • s="Siri's voice recognition is Good" It causes an error because we cannot use double quotes and single quotes simultaneously

Answer :The following expression evaluates to 12 b=False+5-True+35//4 The following line will print result:4.5 print('result:',(7/2)+(False or True)+(9%3))

Consider the python code:
  1. print(10==10 and 20!=20)
  2. print(10==10 or 20!=20)
  3. print( not 10==10)

What is the result?

Options are :

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

Answer :False True False

Which expression would evaluate to 2?


Options are :

  • 11/2
  • 3**2
  • 22%5
  • 13//4

Answer :22%5

Consider the code
  1. x=2
  2. y=6
  3. x+=2**3
  4. x//=y//2//3
  5. print(x)

What is the output?

Options are :

  • 10
  • 9
  • 7
  • 0

Answer :10

Consider the code:
  1. from sys import argv
  2. print(argv[1]+argv[2])

and given the command invocation:py test.py 10 20 What is the result?

Options are :

  • IndexError will be thrown at runtime
  • ImportError will be thrown at runtime
  • 30
  • 1020

Answer :1020

From the sys module, by using which variable we can access command-line arguments?


Options are :

  • argsv
  • argv
  • arguments
  • args

Answer :argv

Consider the code:
  1. lst = [7, 8, 9]
  2. b = lst[:]
  3. print(b is lst)
  4. print(b == lst)

What is the result?

Options are :

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

Answer :False True

Consider the following code:print(type(eval(input('Enter some value:'))))if we enter 10 and 10.0 individually for every run what is the output?


Options are :

Answer :

Which of the following is False?


Options are :

  • A try statement can have one or more except clauses
  • A try statement can have a finally clause without an except clause
  • A try statement can have a finally clause and an except clause
  • A try statement can have one or more finally clauses

Answer :A try statement can have one or more finally clauses

Which type of exception will be raised if we are trying to call a method on the inappropriate object?


Options are :

  • IndexError
  • TypeError
  • AttributeError
  • None of these

Answer :AttributeError

Consider the code
  1. f=open('abc.txt')
  2. f.readall()

Which exception will be raised?

Options are :

  • AttributeError
  • EOFError
  • SystemError
  • SyntaxError

Answer :AttributeError

Consider the code
  1. def f1():
  2. try:
  3. return 1
  4. finally:
  5. return 2
  6. x=f1()
  7. print(x)

What is the result?

Options are :

  • 1
  • 2
  • prints both 1 and 2
  • Error, because more than one return statement is not allowed

Answer :2

Which of the following are True?


Options are :

  • A try block can have any number of except blocks
  • A try block should be associated with atmost one finally block
  • A try block should be associated with atmost one else block
  • All the above

Answer :All the above

The base class for all exceptions in python is:


Options are :

  • ExceptionBase
  • BaseException
  • Exception
  • EOFError

Answer :BaseException

Which of the following is True about else block?


Options are :

  • else block will be executed if there is no exception in try block
  • Without writing except block we cannot write else block
  • For the same try we can write atmost one else block
  • All the above

Answer :All the above

Consider the code:
  1. try:
  2. print('try')
  3. except:
  4. print('except')
  5. else:
  6. print('else')
  7. finally:
  8. print('finally')

What is the result?

Options are :

  • try except else finally
  • try else finally
  • try except finally
  • try finally

Answer :try else finally

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions