- rooms={1:'Left Conference Room',2:'Right Conference Room'}
- room=input('Enter the room number:')
- if not room in rooms:#Line-3
- print('Room does not exist')
- else:
- print('The room name is:'+rooms[room])

The 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 :

- Invalid Syntax
- Mismatched data type(s)
- Misnamed variable(s)
- None of these

Answer :Invalid Syntax

If the book is returned after 9 PM, the student will be charged an extra day. If the Book is rented on a Sunday, the student will get 50% off for as long as they keep the book. If the Book is rented on a Saturday, the student will get 30% off for as long as they keep the book.

We need to write the code to meet these requirements.

# XYZ Book Rented Amount Calculator

- ontime=input('Was Book returned before 9 pm? y or n:').lower()
- days_rented=int(input('How many days was book rented?'))
- day_rented=input('What day the Book rented?').capitalize()
- cost_per_day=3.00
- if ontime == 'n':
- days_rented=days_rented+1
- if day_rented=='Sunday':
- total=(days_rented*cost_per_day)*0.5
- elif day_rented=='Saturday':
- total=(days_rented*cost_per_day)*0.7
- else:
- total=(days_rented*cost_per_day)
- print('The Cost of Book Rental is:$',total)

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:$ 7.0
- The Cost of Book Rental is:$ 8.0
- The Cost of Book Rental is:$ 9.0
- The Cost of Book Rental is:$ 10.0

Answer :The Cost of Book Rental is:$ 9.0

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

- Line-1:
- name=input('Enter Your Name:')
- return name
- Line-2:
- calories=miles*calories_per_mile
- return calories
- distance=int(input('How many miles did you bike this week:'))
- burn_rate= 44
- biker=get_name()
- calories_burned=calc_calories(distance,burn_rate)
- 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):

Options are :

- def get_rating(age): if age>=18: rating="A" elif age>=13: rating="T" else: rating="C" return rating
- def get_rating(age): if age>=18: rating="A" if age>=13: rating="T" else: rating="C" return rating
- def get_rating(age): if age>18: rating="A" elif age>13: rating="T" else: rating="C" return rating
- def get_rating(age): if age>=18: rating="A" elif age>=13: rating="T" else: rating="C" pass rating

Answer :def get_rating(age): if age>=18: rating="A" elif age>=13: rating="T" else: rating="C" return rating

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

- import os
- def get_data(filename,mode):
- if os.path.isfile(filename):
- with open(filename,'r') as file:
- return file.readline()
- else:
- return None

Which of the following are valid about this code?

Options are :

- This function returns the first line of the file if it is available
- This function returns None if the file does not exist
- This function returns total data present in the file
- This function returns the last line of the file

Answer :This function returns the first line of the file if it is available This function returns None if the file does not exist

- inventory=open('inventory.txt','r')
- eof=False
- while eof == False:
- line=inventory.readline()
- if XXX:
- if YYY:
- print(line,end='')
- else:
- print('End of file')
- eof=True
- inventory.close()

Which of the following changes are required to perform to meet the requirements

Options are :

- XXX should be replaced with line != '' YYY should be replaced with line!= '\n'
- XXX should be replaced with the line!= '\n' YYY should be replaced with the line != ''
- XXX should be replaced with the line != '' YYY should be replaced with the line != ''
- XXX should be replaced with the line!= '\n' YYY should be replaced with the line!= '\n'

Answer :XXX should be replaced with the line != '' YYY should be replaced with the line!= '\n'

Options are :

- open('abc.txt','r')
- open('abc.txt','r+')
- open('abc.txt','w+')
- open('abc.txt','w')

Answer :open('abc.txt','w+')

- import os
- def read_file(filename):
- line=None
- if os.path.isfile(file_name):
- data=open(filename,'r')
- while line != '':
- line=data.readline()
- print(line)

The code attempts to read the file even if the file does not exist.You need to correct the code. which lines having identation problems?

Options are :

- First 3 Lines inside the function
- Last 3 Lines inside a function
- Last 2 Lines inside the function
- There is no indentation problem

Answer :Last 3 Lines inside the function

- import sys
- try:
- file_in=open('file1.txt','r')
- file_out=open('file2.txt','w+')
- except IOError:
- print('cannot open',file_name)
- else:
- i=1
- for line in file_in:
- print(line.rstrip())
- file_out.write(str(i)+":"+line)
- i=i+1
- file_in.close()
- file_out.close()

Assume that in.txt file is available, but out.txt file does not exist. Which of the following is true about this code?

Options are :

- This program will copy data from in.txt to out.txt
- The code runs but generates a logical error
- The code will generate a runtime error
- The code will generate a syntax error

Answer :This program will copy data from in.txt to out.txt

Options are :

- math.frexp(x)
- math.floor(x)
- math.fabs(x)
- math.fmod(x)
- math.ceil(x)

Answer :math.floor(x) math.fabs(x)

Options are :

- import math.pow as power
- import pow from math as power
- from math import pow as power
- from math.pow as power

Answer :from math import pow as power

Options are :

- random.randint(18,33)
- random.randint(18,32)
- random.randrange(18,33,1)
- random.randrange(5,11,1)

Answer :random.randint(18,32) random.randrange(18,33,1)

- n=[10,20,30,40,50]
- a=['a','b','c','d','e']
- print( n is a)
- print( n == a)
- n = a
- print( n is a)
- print( n == a)

What is the result?

Options are :

- False False True True
- False True False True
- True False True False
- False True True True

Answer :False False True True

- a=15
- b=5
- print(a/b)

What is the result ?

Options are :

- 3
- 3.0
- 0
- 0.0

Answer :3.0

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

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

Options are :

- y = (x-)**2
- y = -(x)**2
- y = (-x)**2
- y = (x)**-2

Answer :y = (-x)**2

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

What is result value?

Options are :

- 17
- 16
- 18
- 19

Answer :17

- #Code Segment-1
- a1='10'
- b1=3
- c1=a1*b1
- #Code Segment-2
- a2=10
- b2=3
- c2=a2/b2
- #Code Segment-3
- a3=2.6
- b3=1
- c3=a3/b3

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 int type,c3 is of float type
- c1 is of str type,c2 is of float type,c3 is of float type
- c1 is of str type,c2 is of int type,c3 is of int type
- c1 is of str type,c2 is of str type,c3 is of str type

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

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
- Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And Parenthesis
- Parenthesis Exponents Unary Positive, Negative and Not Multiplication and Division Addition and Subtraction And

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

Options are :

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

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

- 01 # The calc_square function calculates exponents
- 02 # x is a first number
- 03 # y is a second number
- 04 # The value of x and y is added and returned
- 05 def calc_power(x, y):
- 06 comment="#Return the value"
- 07 return x + y # Adding x and y

Which of the following statements are true?

Options are :

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

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

`result=a-b*c+d`

Which of the following are valid?

Options are :

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

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

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 at most one else block
- All the above

Answer :All the above

- try:
- print('try')
- print(10/0)
- except:
- print('except')
- else:
- print('else')
- finally:
- print('finally')

What is the result?

Options are :

- try except else finally
- try else finally
- try except finally
- try finally

Answer :try except finally

`x='TEXT'`

which line of the code will assign 'TT' to the output?

Options are :

- output=x[0]+x[-1]
- output=x[1]+x[1]
- output=x[0]+x[2]
- output=x[1]+x[4]

Answer :output=x[0]+x[-1]

- from sys import argv
- sum=0
- for i in range(2,len(argv)):
- sum += float(argv[i])
- print("The Average for {0} is {1:.2f}".format(argv[1],sum/(len(argv)-2)))

Which of the following command invocations will generate the output:The Average for Test is 20.00

Options are :

- py test.py Test 10
- py test.py Test 10 20 30
- py test.py Test 10 20
- py test.py 20

Answer :py test.py Test 10 20 30

- a=['a','b','c','d']
- for i in a:
- a.append(i.upper())
- print(a)

What is the result?

Options are :

- ['a','b','c','d']
- ['A','B','C','D']
- MemoryError thrown at runtime
- SyntaxError

Answer :MemoryError thrown at runtime

- l1=['sunny','bunny','chinny','vinny']
- l2=['sunny','bunny','chinny','vinny']
- print(l1 is l2)
- print(l1 == l2)
- l1=l2
- print(l1 is l2)
- print(l1 == l2)

What is the result?

Options are :

- False True False True
- False False True True
- False True True False
- False True True True

Answer :False True True True

- result=str(bool(1) + float(10)/float(2))
- print(result)

What is the output?

Options are :

- 6.0
- 6
- SyntaxError
- TypeError

Answer :6.0

Options are :

- count=input('Enter count value:') print(count+1)
- count=int(input('Enter count value:')) print(count+1)
- count=eval(input('Enter count value:')) print(count+1)
- count=input('Enter count value:') print(int(count)+1)

Answer :count=int(input('Enter count value:')) print(count+1) count=eval(input('Enter count value:')) print(count+1) count=input('Enter count value:') print(int(count)+1)

- Microsoft Python Certification Exam (98-381) Practice Tests Set 6
- Python Introduction
- Python Installation
- Installing pydev with Eclipse
- Microsoft Python Certification Exam (98-381) Practice Tests Set 3
- Microsoft Python Certification Exam (98-381) Practice Tests Set 2
- Microsoft Python Certification Exam (98-381) Practice Tests Set 1
- Python Generators