PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Medium

Question 34

Q516 - Control Flow


What is the expected output of the following code?


marks = [80, 70, 90, 90, 80, 100]

average = sum(marks) // len(marks)

grade = ''


  • A

    F

  • B

    B

  • C

    C

  • D

    The code is erroneous.

  • E

    D

  • F

    A

Reveal correct answer

Correct answer: B

Explanation

Topics: if elif else list sum() len() chained comparison

Try it yourself:

Explanation:

Here you really have to do a little mental arithmetic.

80 + 70 + 90 + 90 + 80 + 100 -> 510

510 // 6 -> 85

85 is a the grade B


Q516 (Please refer to this number, if you want to write me about this question.)

A. The code calculates the average of the marks and assigns a grade based on the average. As the average does not fall into any of the specified ranges, the default grade 'F' is not the expected output.

B. The code calculates the average of the marks and assigns a grade based on the average. In this case, the average is between 80 and 90, so the grade 'B' is expected as the output.

C. The code assigns grades based on the average calculated from the marks. As the average falls between 70 and 80, the grade 'C' is not the expected output.

D. The code is not erroneous as it correctly calculates the average of the marks and assigns a grade based on the average. The expected output is 'B' based on the average falling between 80 and 90.

E. The code assigns grades based on the average calculated from the marks. Since the average is not between 65 and 70, the grade 'D' is not the expected output.

F. The code is designed to assign grades based on the average calculated from the marks. Since the average falls between 90 and 100, the grade 'A' is not the expected output.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need