π 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:
-
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. -
Print Statement:
The
print()
function is used to display the quote and the author's name on the console. -
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:
- ➤ Exercise 2-1 | Simple Message Part 1
- ➤ Exercise 2-2 | Simple Messages Part 2
- ➤ Exercise 2-3 | Personal Message
- ➤ Exercise 2-4 | Name Cases
- ➤ Exercise 2-5 | Famous Quote
- ➤ Exercise 2-6 | Famous Quote 2
- ➤ Exercise 2-7 | Stripping Names
- ➤ Exercise 2-8 | Number Eight
- ➤ Exercise 2-9 | Favorite Number
- ➤ Exercise 2-10 | Adding Comments
- ➤ Exercise 2-11 | Zen of Python
πTrending Topics
π Connect With Us:
“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
Post a Comment