Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 7 question 336 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 2
Topic #: 7
[All PCEP-30-02 Questions]

What is the expected output of the following code?

  • A. 1 | Hello
    2 | Hello
  • B. 1 | Hello
    2 | Hello
    3 | Hello
  • C. 1 | Hello
    2 | Hello
    3 | Hello
    4 | Hello
  • D. An infinite loop.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Billybob0604
2 days, 19 hours ago
D. just tested it
upvoted 1 times
...
CristinaDev
1 month, 4 weeks ago
Selected Answer: D
D is correct, num never gets updated because it's outside the while which is an endless loop.
upvoted 1 times
...
ellene
5 months, 1 week ago
Let's analyze it: The function func takes two arguments: text and num. Inside the function, there is a while loop that continues as long as num is greater than 0. On each iteration, it prints text and decrements num by 1. When num is no longer greater than 0, the loop exits. When we call func('Hello', 3): num is initially 3. "Hello" is printed, then num becomes 2. num is 2. "Hello" is printed again, then num becomes 1. num is 1. "Hello" is printed once more, then num becomes 0. num is 0, so the loop exits. So the output will be "Hello" printed three times: Copy code Hello Hello Hello Therefore, the correct answer is: B. 1 | Hello 2 | Hello 3 | Hello
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...