Reputation: 51
This is a begginer question. I am writing a text game and have some problems.
code:
def river():
print "You are traveling through deciduous forest."
print "There is nothing going on, except a few squirrels and a hedge."
print "Squirrels are fighting over nuts and a hedge is getting fat eating an apple."
print "Then you see a wide, deep river. The stream is very strong."
print "What are you going to do next?"
print "1. Try to swim the river."
print "2. Watch the squirrels and hedge."
print "3. Turn back."
while True:
choice = raw_input("> ")
if choice == "1" or choice == "swim":
print """You are doing well when in the middle of a river
something begins to bite you near legs. The bitting gets stronger
and you soon realize that piranhas are tearing chunks of your meat
off. Soon there is nothing left of you that the bones. The piranhas
seems satisfied, since they got a free meal."""
dead()
if choice == "2" or choice == "watch":
print "You keep watching animals and are becoming more and more thirsty and hungry."
if choice == "3" or choice == "turn back" or choice == "turn":
start_rewind()
start()
I do not like these print statements. If I use multiline print, like under choice 1, the indentation does not look nice. It is in the same row as def river(). Is this a normal or a bad style? If i indent the text under choice I so it is in the same row as choice 1,.. then it does not look good when i start the script in command promt. How could i solve that?
Thanks
Upvotes: 2
Views: 2355
Reputation: 11
try this:
print("""
You are traveling through deciduous forest.
There is nothing going on, except a few squirrels and a hedge.
Squirrels are fighting over nuts and a hedge is getting fat eating an apple.
Then you see a wide, deep river. The stream is very strong.
What are you going to do next?
1. Try to swim the river.
2. Watch the squirrels and hedge.
3. Turn back.
""")
Upvotes: 1
Reputation: 19320
I would write something like this:
print ("You are traveling through deciduous forest.\n"
"There is nothing going on, except a few squirrels and a hedge.\n"
"Squirrels are fighting over nuts and a hedge is getting fat eating an apple.\n"
"Then you see a wide, deep river. The stream is very strong.")
The parentheses above implicitly continue the string. See the Python docs. For example:
print ("foo "
"bar")
and print "foo bar"
will give the same output. Note the space after "foo".
Note that there is a space between the print
statement and the first parenthesis. In python3, where print
is a function, there should be no space there.
Upvotes: 2