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 41 discussion

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

Which one of the lines should you put in the snippet below to match the expected output?
Expected output:

Code:

  • A. sorted(list)
  • B. sort(list)
  • C. list.sort()
  • D. list.sorted()
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
patonoide
3 weeks, 3 days ago
Selected Answer: C
C is the correct answer as it also saves the result to the variable list. Calling the sorted function does sort the array but does not save it. For sorted to be used it would need to be list = sorted(list).
upvoted 1 times
...
akumo
1 month ago
Selected Answer: A
A. sorted(list) is correct. C. list(sort() will print out None
upvoted 1 times
...
Krish2022
1 month, 1 week ago
Selected Answer: C
Both A & C are correct answer
upvoted 1 times
...
aphg
1 month, 3 weeks ago
Selected Answer: C
Tested the code, C is the correct answer
upvoted 1 times
...
Sam_sgv
3 months, 1 week ago
Selected Answer: C
C is the correct answer, I tested code
upvoted 1 times
...
yagebin
3 months, 3 weeks ago
Selected Answer: C
The correct one is C, only sort method can save the changement
upvoted 2 times
...
hovnival
3 months, 3 weeks ago
Selected Answer: C
To achieve the expected output [1, 2, 4, 7] from the list [2, 7, 1, 4], you should use the list.sort() method, which sorts the list in place. Here is the complete code snippet: Copy list = [2, 7, 1, 4] list.sort() # This sorts the list in place print(list) So, the correct line to use is: C. list.sort()
upvoted 1 times
...
Nfyughguygjhg
4 months, 2 weeks ago
Selected Answer: A
A is correct
upvoted 2 times
...
rcptryk
5 months ago
Selected Answer: C
C is correct because the output expectation must come from print(list) not from the print(sorted(list)). you have to write comment before the print which is list.sort() or you have to write list=sorted(list) which is not option
upvoted 2 times
...
mldprasad
5 months ago
Selected Answer: A
list = [2, 7, 1, 4] print(sorted(list)) So A is correct answer. C output is None
upvoted 3 times
...
Vano1
5 months, 3 weeks ago
Selected Answer: C
The correct answer is C. Checked in Python
upvoted 1 times
...
scriptnone
6 months ago
Selected Answer: A
list = [2, 7, 1, 4] print(sorted(list)) So A is correct answer. C output is None
upvoted 3 times
...
SujPractise
6 months, 3 weeks ago
C will return the sorted list [1, 2, 4, 7]
upvoted 2 times
...
christostz03
8 months ago
c is the correct answer
upvoted 2 times
...
Biju1
8 months, 1 week ago
list.sort() will show none
upvoted 2 times
...
Biju1
8 months, 1 week ago
A is correct
upvoted 3 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago