98-381 Exam QuestionsBrowse all questions from this exam

98-381 Exam - Question 10


HOTSPOT -

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

Exam 98-381 Question 10

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:

Exam 98-381 Question 10
Show Answer
Correct Answer:
Exam 98-381 Question 10

References:

https://www.w3resource.com/python/python-data-type.php

https://www.w3resource.com/python/python-if-else-statements.php

Discussion

13 comments
Sign in to comment
pravesh512
May 5, 2020

3rd one should be mismatch data type..

sadako11
Dec 7, 2020

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.

Shw7
Jul 16, 2021

It is asking to enter Room number, not room name. so we give 1 or 2 which matches with Dict rite?

ben09007
Nov 23, 2021

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

ben09007
Nov 23, 2021

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

samuraipizza26
Jun 25, 2021

100% confident that: int and string string mismatched data type(s)

FuzzyDunlop
Jul 7, 2020

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.

nowisthetime
Jul 20, 2020

There isn't a second issue because it is python dictionaries. so it will see 1 and 2.

Nits0211
Oct 8, 2020

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

Sathish804
Jan 5, 2021

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.

Shanmahi
May 30, 2021

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])

AnuManik
Aug 28, 2021

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"

PavanKumpatlaAccountTwo
Jan 7, 2022

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.

chinna1523
May 8, 2020

rooms = {1: 'Foyer , 2: 'Conference room'} ^ SyntaxError: invalid syntax

AndyV
Jun 28, 2020

You missed to add ' after Foyer, that's why. The answer should be mismatch data your

gargaditya
Oct 11, 2020

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

sana123
Oct 18, 2020

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

hedi12
Mar 17, 2021

correct answer

shtingdcknipples
Mar 20, 2021

All correct

Billian
Mar 22, 2021

How is it marked in the test?