Exercise 2-5 Solution – Python Crash Course Chapter 2: Variables and Simple Data Types

 

📘 Python Crash Course – Chapter 2: Variables and Simple Data Types – Exercise 2-5 Solution


📝 Exercise 2-5

Task: Find a quote from a famous person you admire . Print the quote and the name of its author . Your output should look something like the following, including the quotation marks:
Albert Einstein once said,
“A person who never made a mistake never tried anything new."

✅ Solution Code:


# we use triple quote here
print('''           
Albert Einstein once said,
“A person who never made a mistake never tried anything new."
''')

🧠 Code Explanation:

  1. Triple Quotes for Multiline Strings:

    The code uses triple quotes (''') to define a multiline string. This allows the quote to span multiple lines for better readability.

  2. Print Statement:

    The print() function is used to display the quote and the author's name on the console.

  3. Output:

    When executed, the code will output:

This code demonstrates how to use triple quotes for multiline strings and how to print a formatted message.

🔍 Output:


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

📚 Related Exercises from Chapter 2:


Previous Post Next Post

Contact Form