Reputation: 27
This piece of code is too long in the editor and requires me to scroll to see it. How can I break the code down into multiple lines?
review = raw_input('If the secret number is too high enter h, if the secret number is too low enter l and if it is correct enter c: ')
Upvotes: 0
Views: 610
Reputation: 90889
You can divide the strings up and put each of them in a line of its own -
review = raw_input('If the secret number is too high enter h'
', if the secret number is too low enter l'
'and if it is correct enter c: ')
Example/Demo -
>>> review = raw_input('If the secret number is too high enter h'
... ', if the secret number is too low enter l'
... 'and if it is correct enter c: ')
If the secret number is too high enter h, if the secret number is too low enter land if it is correct enter c: h
>>> review
'h'
To print out on multiple lines, create multiline string, using """
or '''
(three quotes) -
s = '''If the secret number is too high enter h
, if the secret number is too low enter l
and if it is correct enter c: '''
review = raw_input(s)
Example/Demo -
>>> s = '''If the secret number is too high enter h
... , if the secret number is too low enter l
... and if it is correct enter c: '''
>>>
>>> review = raw_input(s)
If the secret number is too high enter h
, if the secret number is too low enter l
and if it is correct enter c: c
>>> review
'c'
I used a separate string just for readability, but you can directly give raw_input()
a multiline string, without having to store it in any variable.
Upvotes: 1
Reputation: 8250
review = raw_input("""If the secret number is too high enter h,
if the secret number is too low enter l
and if it is correct enter c: """)
Use triple quotes for multi-line string.
Upvotes: 0