Python Forum

Full Version: New to python and need help with spacing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
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.
(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.
Pages: 1 2