PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 8


How many lines does the following snippet output?

Show Answer
Correct Answer: B

The code snippet has a for loop that iterates over the range (1, 3), which means it will run for i=1 and i=2. In each iteration, print('*', end='') will execute, which prints '*' without moving to a new line. After the loop, the else clause will execute, printing '*' and moving to a new line. Therefore, the entire output will be '***' on a single line.

Discussion

17 comments
Sign in to comment
Tarun1Option: B
Mar 9, 2020

its one line

AvidulamOption: B
Mar 10, 2020

It prints only in one line

N9Option: B
Sep 3, 2022

3 stars in one line

naveenbv80Option: A
Dec 2, 2022

for i in range (1,3): print("*", end="") else: print("*") Answer is ***

mplopezOption: A
Jul 22, 2023

The correct answer is A. The snippet returns ***.

mplopez
Jul 22, 2023

It only works the for loop, the else part is no needed in this case because you didn't have any way to take.

peypaOption: C
Mar 12, 2024

range Starts at 1 and ends at 2

666_mOption: A
May 5, 2022

A is correct

SuvabrataOption: A
Jun 13, 2022

A is correct...It will print ***

beshaOption: B
Jul 2, 2022

one line and 3 stars

spiderking123Option: B
Mar 5, 2023

Answer is one line

DinshaOption: B
Mar 8, 2023

The * will print in one line

CristianCruzOption: D
Jul 12, 2023

answer is D

DempsdawgOption: B
Mar 21, 2024

Answer is B

86b907fOption: B
Jun 10, 2024

Only one line ...

IshanKarpeOption: A
Jul 12, 2024

Stop Lying. IT DOES NOT PRINT 1, IT PRINTS THREE BC OF ELSE STATEMENT> TRIED AND TESTED

IshanKarpeOption: A
Jul 12, 2024

Three lines, elseincluded