Output should look like a quotation

154 Views Asked by At

I am trying to print a quotation and the name of the author. My output should look something like the following (including the quotation):

Albert Einstein once said, "A person who never made a mistake never tried anything new."

I tried this:

quote = "A person who never made a mistake never tried anything new."
message = f"Albert Einstein once said, {quote}"
print(message)

But I am not getting quotation, the rest is fine I think.

5

There are 5 best solutions below

1
On BEST ANSWER

You can do something like this:

>>> quote = "\"A person who never made a mistake never tried anything new.\""
>>> message = f"Albert Einstein once said, {quote}"
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

Or you can also do something like this:

>>> quote = "A person who never made a mistake never tried anything new."
>>> message = f"Albert Einstein once said, \"{quote}\""
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

Or you can wrap the double quotes with a single quote to get you to print the double quotes.

Do something like this:

>>> quote = '"A person who never made a mistake never tried anything new."'
>>> message = f"Albert Einstein once said, {quote}"
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

Note that if you have a single quote inside your sentence, then it will not work. For example, if your sentence said "A person who's never made a mistake never tried anything new", then the single quote won't work.

3
On

You need put backslash before the quotation marks.

print("test test hello /" very good /" said him")

Output:

test test hello " very good " said him

1
On

Try with

quote = '"A person who never made a mistake never tried anything new."'
message = "Albert Einstein once said, {}".format(quote)
print(message)
0
On

Try this

 quote = '"A person who never made a mistake never tried anything new."'
 message = f"Albert Einstein once said, {quote}"
 print(message)
0
On

Try this:

a = "Albert Einstein once said, \"A person who never made a mistake never tried anything new.\""
print(a)

or:

a = 'Albert Einstein once said,"A person who never made a mistake never tried anything new."'
print(a)