Python Forum
New to python and need help with spacing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to python and need help with spacing
#11
what u need to do is double up the "\"
string = """GIS GIS GIS GIS GIS GIS GIS
GIS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\GIS
GIS\\\\\\\\\\\\\\\\\\GIS\\\\\\\\\\\\\\\\\\GIS
GIS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\GIS
GIS GIS GIS GIS GIS GIS GIS"""

print(string)
Output:
GIS GIS GIS GIS GIS GIS GIS GIS\\\\\\\\\\\\\\\\\\\\\GIS GIS\\\\\\\\\GIS\\\\\\\\\GIS GIS\\\\\\\\\\\\\\\\\\\\\GIS GIS GIS GIS GIS GIS GIS GIS
Reply
#12
For me it smells like homework. So I provide one partial way to do it - how to print rectangle, but without center.

def do_rectangle(height=5, width=7, characters='GIS'):
    inner_width = len(characters) * (width - 2) + width - 1
    for i in range(height):
        if i in (0, height-1):
            print(' '.join(characters for i in range(width)))
        else:
            print(f'{characters}{" "*inner_width}{characters}')

do_rectangle()        
do_rectangle(height=5, width=5, characters='*')
Output:
GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS GIS * * * * * * * * * * * * * * * *
It's matter of defensiveness how to deal with negative width.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#13
(Sep-12-2021, 04:35 AM)naughtyCat Wrote: what u need to do is double up the "\"
The poster has stated multiple times the backslashes are supposed to be spaces, and that backslashes are only there because spaces get collapsed in the post.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Latex spacing question StillAnotherDave 0 1,473 Mar-28-2020, 05:51 PM
Last Post: StillAnotherDave

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020