PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 7


What is the expected output of the following snippet?

Show Answer
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

17 comments
Sign in to comment
mplopezOption: A
Jul 22, 2023

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
Nov 7, 2022

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

Rizos
Mar 15, 2023

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

andr3
Mar 19, 2023

how many new questions was on exam ?

Rizos
Mar 20, 2023

maybe 20

andr3
Mar 21, 2023

thanks and good luck next time

macxszOption: A
May 3, 2022

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

Valcon_doo_NoviSadOption: A
Oct 24, 2023

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

DempsdawgOption: A
Mar 21, 2024

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

MoonusOption: A
Sep 17, 2021

Answer is A

technoguyOption: A
Nov 27, 2021

a is correct since the equality operator is wrong

rocky48Option: A
Mar 10, 2022

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:

Ram5678Option: A
Apr 26, 2022

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

666_mOption: A
May 5, 2022

A is correct , for reason of invalid synthax

N9Option: A
Sep 3, 2022

A is correct. == is required.

DinshaOption: A
Mar 8, 2023

It will throw error while exe ution

DrMKG
May 24, 2023

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

Ello2023Option: A
Jun 13, 2023

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

Administrator_Of_Silly_WalksOption: A
Jul 11, 2023

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
Sep 20, 2023

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

CristianCruzOption: B
Jul 12, 2023

answer is B

Kusme
Aug 27, 2023

the answer is 2, I ran in IDE