PCEP 30 02 PCEP Certified Entry Level Python Programmer · Free Practice Question Easy
Question 25
What will be the output of the following code snippet when the user enters 'secret'?
- while True:
- code = input("What is the secret code? ")
- if code == 'secret':
- print("valid code -",code)
- break
- print("Bye")
- else:
- print("Invalid code -", code)
-
A
Invalid Code - secret -
B
- valid code - secret
- Bye
-
C
- valid code -,secret
- Bye
-
D
valid code - secret
Reveal correct answer
Correct answer: D
Explanation
As, secret == secret will be True, so it prints -
valid code - secret
It encounters the break statement and the loop is terminated.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
