Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 1 question 7 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 7
Topic #: 1
[All PCEP-30-02 Questions]

What is the output of the following snippet?

  • A. 12
  • B. (2, 1)
  • C. (1, 2)
  • D. 21
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
consultsk
1 month, 3 weeks ago
Selected Answer: D
To determine the output of this code, let's go through it step by step: dct = {} creates an empty dictionary. dct['1'] = (1, 2) adds a key-value pair to the dictionary. The key is the string '1', and the value is the tuple (1, 2). dct['2'] = (2, 1) adds another key-value pair. The key is the string '2', and the value is the tuple (2, 1). The for loop iterates over the keys of the dictionary using dct.keys(). For each key x, it prints dct[x][1] with end=''. This means it's printing the second element of each tuple (index 1), and the end='' argument prevents a newline after each print. So, when we iterate over the keys: For key '1', it will print 2 (the second element of (1, 2)) For key '2', it will print 1 (the second element of (2, 1)) These will be printed on the same line because of end=''. Therefore, the output will be: 21
upvoted 1 times
...
megan_mai
3 months ago
Selected Answer: D
dct = {} dct['1'] = (1,2) #second element of this key is 2 dct['2'] = (2,1) #second element of this key is 1 for x in dct.keys(): print(dct[x][1], end='') #print out the second element of each key continuously #>>> the answer is 21 (D)
upvoted 1 times
...
christostz03
3 months ago
d is the correct answer
upvoted 1 times
...
froster02
4 months, 1 week ago
answer : 21 2 is of the dct['1'] and 1 is of dct['2']
upvoted 1 times
...
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.

SaveCancel
Loading ...