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)
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)
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.
option c d has key without quote. so it is not correct key
Of course AB, according given criteria. CD could work also if Mom and Dad are classes but this isn't mentioned in question.
It does say "...assume no other items have been created before" though, so those shouldn't be classes.
so crazy, who set the correct answers to CD??? you go try it
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.
A. dir={'Mom': 5551234567, 'Dad': 5557654321} B. dir= {'Mom': '5551234567', 'Dad': '5557654321'}
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
Correct answer is A and B, as keys should be "quoted"
Correct answer are A and B
Correct answer are A and B
key needs quote
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)
Key need quote e.g. 'Mom' : value
C and D has Key without quotes. So answer should be A and B
option A and B is right
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.