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)
A.
dir={'Mom': 5551234567, 'Dad': 5557654321}
B.
dir= {'Mom': '5551234567', 'Dad': '5557654321'}
Correct: A,B
print("A.",{'Mom': 5551234567, 'Dad': 5557654321})
print("B.", {'Mom': '5551234567', 'Dad': '5557654321'})
#print("C.", {Mom: 5551234567, Dad: 5557654321}) # NameError: name 'Mom' is not defined
#print("D.", {Mom: '5551234567', Dad: '5557654321'}) # NameError: name 'Mom' is not defined
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
"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
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.
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.
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.
This section is not available anymore. Please use the main Exam Page.PCAP Exam Questions
Log in to ExamTopics
Sign in:
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.
technoguy
Highly Voted 3 years, 4 months agoJeyTlenJey
Most Recent 8 months, 4 weeks agoSanela
11 months, 1 week ago25Topaz
1 year, 4 months agoJeffriXu
1 year, 5 months agoValcon_doo_NoviSad
1 year, 6 months agoAcid_Scorpion
1 year, 6 months agoSadaiyan
1 year, 11 months agodicksonpwc
2 years agoNorbiox
2 years, 4 months agoValcon_doo_NoviSad
1 year, 6 months agojaimebb
2 years, 5 months agoHanjito
2 years, 6 months agoN9
2 years, 7 months agoJnanada
2 years, 8 months agoPremJaguar
2 years, 9 months agoVan_Rossum
2 years, 9 months agoSuvabrata
2 years, 10 months ago