-4

I want to print the following output in python:

 99 buckets of bits on the bus.
 99 buckets of bits.
 Take one down, short it to ground.
 98 buckets of bits on the bus.

with a single print command and no "\n" characters in between. How can this be done?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Sulav Timsina
  • 703
  • 7
  • 20

3 Answers3

5

With triple-quoted string literals, you can use actual newlines instead of \n.

print(""" 99 buckets of bits on the bus.
 99 buckets of bits.
 Take one down, short it to ground.
 98 buckets of bits on the bus.""")
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
4
import os
print os.linesep.join(["99 buckets of bits on the bus.",
 "99 buckets of bits.",
 "Take one down, short it to ground.",
 "98 buckets of bits on the bus."])
wim
  • 338,267
  • 99
  • 616
  • 750
Paul Becotte
  • 9,767
  • 3
  • 34
  • 42
0

This seems to work:

print chr(10).join([
    '99 buckets of bits on the bus.',
    '99 buckets of bits.',
    'Take one down, short it to ground.',
    '98 buckets of bits on the bus.'
])
101
  • 8,514
  • 6
  • 43
  • 69