BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Python Institute PCEP-30-02 Exam - Topic 1 Question 5 Discussion

Posted by Laticia on Oct 18, 2023 at 05:42 PM

What is the expected output of the following code?

Suggested Answer: C

The code snippet that you have sent is a loop that checks if a variable ''floor'' is less than or equal to 0 and prints a string accordingly. The code is as follows:

floor = 5 while floor > 0: print(''+'') floor = floor - 1

The code starts with assigning the value 5 to the variable ''floor''. Then, it enters a while loop that repeats as long as the condition ''floor > 0'' is true. Inside the loop, the code prints a ''+'' symbol to the screen, and then subtracts 1 from the value of ''floor''. The loop ends when ''floor'' becomes 0 or negative, and the code exits.

The code outputs five ''+'' symbols to the screen, one for each iteration of the loop. Therefore, the correct answer is C. five.


Get Premium PCEP-30-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
36 comments · newest first
MI
Misty 12 months ago
I agree with A, it should just return 1.
JI
Jin 1 year ago
Wait, is it really D? That seems off.
FA
Fannie 1 year ago
I’m leaning towards C, but not sure.
CO
Corazon 1 year ago
Definitely B, it throws an exception!
TR
Tracie 1 year ago
I think the output is D.
VA
Vanna 1 year ago
I practiced a question like this before, and I think it was about returning a tuple, so D seems likely.
SA
Sarah 1 year ago
I feel like the answer could be False, but I can't recall the exact logic behind it.
FE
Felicidad 1 year ago
I remember something about exceptions in similar questions, so maybe it raises an unhandled exception instead?
GE
Geoffrey 1 year ago
I think the output might be option D, but I'm not entirely sure if the tuple is formatted correctly.
FR
Frederic 1 year ago
This is a good test of my knowledge. I'm confident I can work through this step-by-step and arrive at the correct answer.
VA
Vanesa 1 year ago
Okay, let me break this down. The code is creating a tuple, so the output should be a tuple. I just need to figure out the exact values that will be in the tuple.
AR
Armanda 1 year ago
Ah, I think I've seen something like this before. Let me quickly review the rules around string concatenation and boolean values in this language.
SA
Sang 1 year ago
I'm not entirely sure about this one. The output seems a bit ambiguous, so I'll need to double-check my understanding of the language features involved.
KE
Kenia 1 year ago
Hmm, this looks like a tricky one. I'll need to carefully read through the code and think through the logic step-by-step.
CA
Caitlin 1 year ago
I'm pretty confident about this one. I know CASE and DECODE are both SQL functions, so I'll start by evaluating the statements about them being functions.
SH
Sharen 1 year ago
This is a good test of my XSLT knowledge. I'm feeling confident that I can figure out the right answer if I take my time and think it through.
JU
Jules 1 year ago
No way, objects should never call other objects. That's a recipe for a tangled mess of dependencies. I'm going with option A.
JA
Jame 1 year ago
I'm pretty sure this is asking about the type of query needed for a Prisma Cloud build policy in Terraform. I think the answer is Terraform, since Prisma Cloud integrates with Terraform.
AS
Ashleigh 2 years ago
This question is a real star-studded affair, isn't it? I bet the answer is out of this world!
AL
Alex 2 years ago
Hold up, I'm pretty sure it's just a single star. D all the way!
ME
Melvin 1 year ago
↳ replying to Alex
No way, it's definitely just one star, D) *
ME
Melvin 1 year ago
↳ replying to Alex
I think it's actually three stars, so B) * * *
MA
Marla 2 years ago
I'm with Pete on this one. The pattern is obvious. * * *
JE
Jerry 1 year ago
↳ replying to Marla
The expected output is B) * * *
ZO
Zona 1 year ago
↳ replying to Marla
Yes, it's definitely B) * * *
LU
Luisa 2 years ago
↳ replying to Marla
I agree, the pattern is clear. It should be B) * * *
CA
Catherin 2 years ago
↳ replying to Marla
I think the answer is B) * * *
AN
Antonio 2 years ago
But the code only prints one asterisk, so the answer should be D)
PE
Pearline 2 years ago
I disagree, I believe the answer is D) *
PE
Pete 2 years ago
The output is clearly three stars, so it's gotta be B.
ER
Ernest 1 year ago
↳ replying to Pete
Yes, the correct answer is B) * * *
JE
Jessenia 1 year ago
↳ replying to Pete
The code definitely produces three stars as output.
SH
Shantell 2 years ago
↳ replying to Pete
I agree, it looks like the code will output three stars.
BO
Bo 2 years ago
↳ replying to Pete
I think the answer is B) * * *
CO
Corazon 2 years ago
Hmm, looks like a tricky one. Gotta think through this carefully.
AN
Antonio 2 years ago
I think the answer is C) * *
0/2000 characters

Save Cancel