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

Question 38

Q497 - Control Flow


What is the expected output of the following snippet?



  • A

    ABC

  • B

    The code will cause a runtime exception.

  • C

    abc

  • D

    123

Reveal correct answer

Correct answer: B

Explanation

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

A.

The code will cause a runtime exception because the len() function returns the length of the string s, which is an integer. The for loop requires an iterable object, such as a list, tuple, or string, to iterate over its elements. Trying to iterate over an integer will result in a TypeError.

B. The code will cause a runtime exception because the len() function returns the length of the string s, which is an integer. The for loop requires an iterable object, such as a list, tuple, or string, to iterate over its elements. Trying to iterate over an integer will result in a TypeError.

C.

The code will cause a runtime exception because the len() function returns the length of the string s, which is an integer. The for loop requires an iterable object, such as a list, tuple, or string, to iterate over its elements. Trying to iterate over an integer will result in a TypeError.

D.

The code will cause a runtime exception because the len() function returns the length of the string s, which is an integer. The for loop requires an iterable object, such as a list, tuple, or string, to iterate over its elements. Trying to iterate over an integer will result in a TypeError.

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