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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started