Python - Multiple line printed image not displaying correctly issues

Question!

I am having some issues with displaying images for Rock - Paper - Scissors. I'm very new to python (3 weeks) and I am trying to print a multiple line 'image'.
Please excuse my terrible art!

import random

def Display_Rock():
    print ("""\n
   _---___
  / .#.... \
 / .$../\.. \
 |_________/
""")

def Display_Paper():
    print ("""\n
 __________
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|  
|~~~~~~~~~~| 
|__________|
""")

def Display_Scissors():
    print ("""\n

    _----_
   / /--\ \     
  |  \__/  \_________________
   \____                     \
    /       ------------------\
   /  /--\  _________________/
   |  \__/  /
    \-____-/          
 """)
 Display_Rock()
 Display_Scissors()
 Display_Paper()

This displays the following -

   _---___
 / .#.... / .$../\.. |_________/




         ----_
       / /--\ \     
      |  \__/  \_________________
       \____                       /       ------------------ / /--\   
      _________________/            
      |  \__/  /
       \-____-/          



       __________
      |~~~~~~~~~~|
      |~~~~~~~~~~|
      |~~~~~~~~~~|
      |~~~~~~~~~~|
      |~~~~~~~~~~|  
      |~~~~~~~~~~| 
      |__________|

Thank you for reading and for any comments in advance!



Answers

While the others are correct, you can also escape the \ so that it is not treated specially by adding another \:

print ("""\n

    _----_
   / /--\ \\     
  |  \__/  \_________________
   \____                     \\
    /       ------------------\\
   /  /--\  _________________/
   |  \__/  /
    \-____-/          
""")

In future Python versions the \ cannot be used unescaped, so starting from 3.6 a warning will be emitted for \_, \- and \, so from there on you must always use \\ to mean \; alternatively you can use the r'' raw strings; though then you cannot use \n for newline.



Use r before of your strings like so:

def Display_Rock():
    print (r"""
   _---___
  / .#.... \
 / .$../\.. \
 |_________/
""")

>>> Display_Rock()

   _---___
  / .#.... \
 / .$../\.. \
 |_________/

Python treats your \ as escape chars.

By : Bharel


Some options:

  • Use R#. Then when you're about to add the a++;, first type an opening brace with the cursor just before the 'r' of return and it will add the closing brace for you, and when you then hit Enter you're ready to type a++;. Just 1 or 2 keystrokes depending on what you want. (This is configurable in R# so your mileage will depend on that).

  • Subjective perhaps, but this is one of the good reasons to not write code like the original in the first place, and to instead use braces for even a single statement block. If that's too unpalatable for you, put single statements on the same line as the if()

By : sellotape


This video can help you solving your question :)
By: admin