Question: Write a program that reads two lines and determines if it is a legal string enclosed within single or double quotes. The program should print

Write a program that reads two lines and determines if it is a legal string enclosed within single or double quotes. The program should print only one output: True or False and exits.

The following is a table of escape sequences which cause Python to suppress the usual special interpretation of a character in a string:

Escape

Sequence Usual Interpretation of

Character(s) After Backslash Escaped Interpretation

\' Terminates string with single quote opening delimiter Literal single quote (') character

\" Terminates string with double quote opening delimiter Literal double quote (") character

ewline Terminates input line Newline is ignored

\\ Introduces escape sequence Literal backslash (\) character

To break up a string over more than one line, include a backslash before each newline, and the newlines will be ignored:

>>> 'a\

... b\

... c'

For example :

User inputs:

'abc\

def'

return True

'abc

def'

return False

'abc\def

gh'

return False

'abc\'

def'

return False

'abc\'\

def'

return True

'abc'

(nothing inputted for line 2)

return True

'abc'

''CSE"

return False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!