exam questions

Exam 98-381 All Questions

View all questions & answers for the 98-381 exam

Exam 98-381 topic 1 question 10 discussion

Actual exam question from Microsoft's 98-381
Question #: 10
Topic #: 1
[All 98-381 Questions]

HOTSPOT -
You create the following program to locate a conference room and display the room name. Line numbers are included for reference only.

Colleagues report that the program sometimes produces incorrect results.
You need to troubleshoot the program. Use the drop-down menus to select the answer choice that answers each question based on the information presented in the code segment.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
References:
https://www.w3resource.com/python/python-data-type.php
https://www.w3resource.com/python/python-if-else-statements.php

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
pravesh512
Highly Voted 5 years, 1 month ago
3rd one should be mismatch data type..
upvoted 25 times
...
sadako11
Highly Voted 4 years, 6 months ago
Is not invalid syntax. The syntax is fine. The line if not room in rooms: does not throw any errors. The problem is that room is a string and the dictionary rooms keys are integers so a match will never be found. The problem is a mismatch data type.
upvoted 10 times
Shw7
3 years, 10 months ago
It is asking to enter Room number, not room name. so we give 1 or 2 which matches with Dict rite?
upvoted 1 times
ben09007
3 years, 6 months ago
In line 2, room is a string. So even if you enter 1 or 2, it will be considered a string. Since line 2 input only takes in string values. So in line 3, it is comparing string 2 to int 2, which will cause a mismatch data type error
upvoted 1 times
...
...
...
PavanKumpatlaAccountTwo
Most Recent 3 years, 5 months ago
3rd one should actually be Mismatch Data Type since the code doesn't actually give any errors for invalid syntax. It works fine but the real problem is that the user input will always be in "string" form no matter how they type it in. It needs to be converted into "integer" form.
upvoted 2 times
...
samuraipizza26
3 years, 11 months ago
100% confident that: int and string string mismatched data type(s)
upvoted 4 times
...
Billian
4 years, 2 months ago
How is it marked in the test?
upvoted 1 times
...
shtingdcknipples
4 years, 2 months ago
All correct
upvoted 1 times
...
hedi12
4 years, 2 months ago
correct answer
upvoted 1 times
...
Sathish804
4 years, 5 months ago
Invalid Syntax is correct. If we want to iterate on the Keys or items we need to use dictionary.keys() or dictionary.items() to loop on them. In the question it should be "room in rooms.keys()", so its a invalid Syntax.
upvoted 2 times
Shanmahi
4 years ago
Nope. If you simply update line 02 to take int as input, the code will display the room name. No issue with line 03 syntax. I have executed the code below and it worked! rooms = {1: 'Lab', 2: 'Conf'} room = int(input('enter the room number: ')) if room not in rooms: print('room number does not exist') else: print("the room name is: " + rooms[room])
upvoted 4 times
...
AnuManik
3 years, 9 months ago
Nope. If you write the code like this rooms = {'1': 'Foyer', '2': 'Conference'} then you will be getting the answer like "The room name is Foyer". Anyway rooms.keys() returns the datatype is int. but room variable's datatype is string. So answer should be mismatched data type(s) though i am not getting any error only getting "room number does not exist"
upvoted 1 times
...
...
sana123
4 years, 7 months ago
first program will try to check syntax(if room not in rooms:) then data type so if we need to choose 1 option it will be invalid syntax
upvoted 1 times
...
gargaditya
4 years, 8 months ago
Line 03 fails because of both syntax error as well as data type mismatch: 1. line 02 needs integer conversion of the string: room=int(input('Enter the room number: ')) 2.Line 03 needs syntax: if room not in rooms: ------------------------ Not sure which one to choose? P.S.ITs a dictionary,so rooms[room] is referring to the key value unlike a list which has fixed index numbering that too starting at 0
upvoted 1 times
...
Nits0211
4 years, 8 months ago
Line 03 - if not room in rooms: The problem is with the above line it is syntax issue - as the program won't compile, it should be "if room not in rooms:"
upvoted 2 times
...
FuzzyDunlop
4 years, 11 months ago
It won't find the room number because the input returns a string value that it's using to match against the int keys in the dictionary (e.g. "1" can't find the first room with a key of 1). So the issue is a mismatched data type. However, I also see a second issue here, in the else statement it uses the room variable to print the room name from rooms, but the room numbers are 1 and 2, whereas the indexes for those rooms are 0 and 1.
upvoted 2 times
nowisthetime
4 years, 10 months ago
There isn't a second issue because it is python dictionaries. so it will see 1 and 2.
upvoted 2 times
...
...
chinna1523
5 years, 1 month ago
rooms = {1: 'Foyer , 2: 'Conference room'} ^ SyntaxError: invalid syntax
upvoted 1 times
AndyV
4 years, 11 months ago
You missed to add ' after Foyer, that's why. The answer should be mismatch data your
upvoted 2 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...