Exam PCAP All QuestionsBrowse all questions from this 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)

    Correct Answer: A, B

    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
technoguyOptions: AB

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

NorbioxOptions: AB

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

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

JeffriXuOptions: AB

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

Valcon_doo_NoviSadOptions: AB

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.

macxszOptions: AB

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

SanelaOptions: AB

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

25TopazOptions: AB

"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

Acid_ScorpionOptions: AB

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

SadaiyanOptions: AB

Correct answer are A and B

dicksonpwcOptions: AB

Correct answer are A and B

jaimebbOptions: AB

key needs quote

HanjitoOptions: AB

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)

N9Options: AB

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

JnanadaOptions: AB

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

PremJaguarOptions: AB

option A and B is right

Van_RossumOptions: AB

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.

SuvabrataOptions: AB

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.