Bird
Raised Fist0

You want to write a Python script that prints a poem with multiple lines exactly as shown below:

hard🚀 Application Q8 of Q15
Python - File Reading and Writing Strategies
You want to write a Python script that prints a poem with multiple lines exactly as shown below:
Roses are red
Violets are blue
Sugar is sweet
And so are you
Which code snippet will produce this output correctly?
Aprint('Roses are red\nViolets are blue\tSugar is sweet\nAnd so are you')
Bprint('Roses are red Violets are blue Sugar is sweet And so are you')
Cprint('Roses are red\tViolets are blue\tSugar is sweet\tAnd so are you')
Dprint('Roses are red\nViolets are blue\nSugar is sweet\nAnd so are you')
Step-by-Step Solution
Solution:
  1. Step 1: Understand escape sequences for new lines

    \n creates a new line; \t creates a tab space.
  2. Step 2: Check which option prints lines exactly as shown

    print('Roses are red\nViolets are blue\nSugar is sweet\nAnd so are you') uses \n correctly for all line breaks; others use spaces or tabs incorrectly.
  3. Final Answer:

    print('Roses are red\nViolets are blue\nSugar is sweet\nAnd so are you') -> Option D
  4. Quick Check:

    Use \n for line breaks in strings [OK]
Quick Trick: Use \n to print each line separately [OK]
Common Mistakes:
MISTAKES
  • Using spaces instead of \n
  • Using \t instead of \n
  • Mixing tabs and new lines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes