Exam PCAP All QuestionsBrowse all questions from this exam
Question 7

What is the expected output of the following snippet?

    Correct Answer: A

    The code contains a syntax error. Specifically, the comparison within the if statement uses a single equals sign (i % 2 = 0) which is incorrect for equality comparison in Python. It should use a double equals sign (i % 2 == 0). Therefore, the code will not run and will raise a syntax error. Hence, the expected output is that the code is erroneous.

Discussion
mplopezOption: A

In this case, the correct answer is A, because inside the if for comparing the result of the modulus must be if i % 2 == 0: .....

Raeesa

I wrote a few days ago. There are no identation or 'issues ==' typos in the exam.

Rizos

This is true, I took the exam and failed. There are no typos or indentation issues.

andr3

how many new questions was on exam ?

Rizos

maybe 20

andr3

thanks and good luck next time

DempsdawgOption: A

The answer is A because it says "i%2=0" which causes a a error. it should be "i%2==0"

Valcon_doo_NoviSadOption: A

Answer is A because we have "if i % 2 = 0" and it should be "if i % 2 == 0" Even if we had if i % 2 == 0 having break command inside skips the else block

macxszOption: A

should be if == answer: A. the code is erroneous

Kusme

the answer is 2, I ran in IDE

CristianCruzOption: B

answer is B

Administrator_Of_Silly_WalksOption: A

There are two major typos that I can see: 1) "if i % 2 = 0" should be "if i % 2 == 0" 2) The "if" and "else" statements aren't lined up correctly.

Almartmart

The second one isn't a typo. The else is part of the while, which gets executed the moment that you exit the loop.

Ello2023Option: A

A. the code is erroneous There is no indentation error, however the line that has % 2 = 0 should be % 2 == 0

DrMKG

Answer is 2 (with correction of code typo and indentation)

DinshaOption: A

It will throw error while exe ution

N9Option: A

A is correct. == is required.

666_mOption: A

A is correct , for reason of invalid synthax

Ram5678Option: A

A is correct as the equality operator is wrong. It is supposed to be a == 5.

rocky48Option: A

Notice that the following snippet is: if i%2=0: that raise a SyntaxError You would be right if the snippet were: if i % 2 == 0:

technoguyOption: A

a is correct since the equality operator is wrong

MoonusOption: A

Answer is A