PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 20


You need data which can act as a simple telephone directory. You can obtain it with the following clauses (Choose two.) (assume that no other items have been created before)

Show Answer
Correct Answer: AB

In Python, dictionaries store key-value pairs. Keys, especially when they are strings, must be quoted. Therefore, 'Mom' and 'Dad' should be in quotes. Both A and B quote the keys correctly, making them valid dictionary definitions. C and D are incorrect because 'Mom' and 'Dad' are not quoted, so they are treated as undefined variables, which would result in an error.

Discussion

17 comments
Sign in to comment
technoguyOptions: AB
Nov 27, 2021

option c d has key without quote. so it is not correct key

NorbioxOptions: AB
Dec 17, 2022

Of course AB, according given criteria. CD could work also if Mom and Dad are classes but this isn't mentioned in question.

Valcon_doo_NoviSad
Oct 10, 2023

It does say "...assume no other items have been created before" though, so those shouldn't be classes.

macxszOptions: AB
May 3, 2022

A. dir={'Mom': 5551234567, 'Dad': 5557654321} B. dir= {'Mom': '5551234567', 'Dad': '5557654321'}

Valcon_doo_NoviSadOptions: AB
Oct 10, 2023

A lot of correct answers in the comments are wrong in one thing - a dictionary key does not have to be quoted, unless it's a string. It is an important distinction to saying "keys should be quoted" which is not the case.

JeffriXuOptions: AB
Nov 6, 2023

so crazy, who set the correct answers to CD??? you go try it

SuvabrataOptions: AB
Jun 3, 2022

Correct answers are A and B. Since the keys in a dictionary should be in quotes, so C and D are incorrect. The values in a dictionary may or may not be under quotes, so A and B are correct.

Van_RossumOptions: AB
Jul 2, 2022

Note the condition: "..no other items have been created before." Without enclosing Mom and Dad inside quotes(to make then string literals), they remain undefined variables.

PremJaguarOptions: AB
Jul 18, 2022

option A and B is right

JnanadaOptions: AB
Aug 18, 2022

C and D has Key without quotes. So answer should be A and B

N9Options: AB
Sep 3, 2022

Key need quote e.g. 'Mom' : value

HanjitoOptions: AB
Sep 27, 2022

Keys without quotes won't work, it's A and B. In C and D, Mom and Dad represent variables that are not defined (error)

jaimebbOptions: AB
Nov 12, 2022

key needs quote

dicksonpwcOptions: AB
Apr 20, 2023

Correct answer are A and B

SadaiyanOptions: AB
May 9, 2023

Correct answer are A and B

Acid_ScorpionOptions: AB
Sep 25, 2023

Correct answer is A and B, as keys should be "quoted"

25TopazOptions: AB
Dec 16, 2023

"NameError: name 'Mom' is not defined " will happen as it will as it it will think Mom is a variable that is undefined since it is not in '' or "" like string should be

SanelaOptions: AB
May 18, 2024

A dictionary cannot hold variable as key (since no other items have been created before), so C and D aren't correct answers. Keys should be literals here