Question:

Consider the statements given below and then choose the correct output from the given options:
N = '5'
try:
    print('WORD' + N, end='#')
except:
    print('ERROR', end='#')
finally:
    print('OVER')

Show Hint

The finally block always runs,
regardless of whether an exception occurs or not.
Always use matching data types when concatenating strings.
  • ERROR#
  • WORD5#OVER
  • WORD5#
  • ERROR#OVER
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

The variable N is a string with the value `'5'`.
Inside the try block, print('WORD' + N, end='#') concatenates `'WORD'` and `'5'`.
Since both are strings, the concatenation works without error.
So, `'WORD5'` is printed followed by `#`.
Since no exception occurs, the except block is skipped.
The finally block always executes, so `'OVER'` is printed immediately after.
The final output is `'WORD5#OVER'`.
Therefore, option (B) is the correct answer.
Was this answer helpful?
0
0

Top Questions on Programming in Python

View More Questions

Questions Asked in CBSE CLASS XII exam

View More Questions