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:


“In the world of code, Python is the language of simplicity, where logic meets creativity, and every line brings us closer to our goals.”— Only Python

πŸ“Œ Follow Us And Stay Updated For Daily Updates

Comments