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
I am trying to create a script that will take the users input and arrange the input in this manner. GIS being what the user input is. NOTE: I had to put the forward slashes\\\\ in the place of blank spaces. Because when I would preview the post it would close up lines 2, 3, 4. It should be just open spaces for example on line 2 it should have nothing but blank spaces in place of the \\\.

GIS GIS GIS GIS GIS GIS GIS
GIS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\GIS
GIS\\\\\\\\\\\\\\\GIS\\\\\\\\\\\\\\\\GIS
GIS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\GIS
GIS GIS GIS GIS GIS GIS GIS

I am able to get it to create the first line but very lengthy and there has to be a shorter way. Here is what I have.

x = raw_input ("What are your initials? ")
print x , x , x , x , x , x , x ,
Is this the only way, if so how do I add all the blanks spaces for the next line.
quick edit I am using Python 3.9
Thanks in advance for any help.
Is it Python 2?

You should think it through before starting to code. If you take input from user, then it could be one character or five or whatnot. This means that number of spaces depends from user input length. As of printing spaces - this can be done in similar fashion as with any other character.
Using python 3
user_input = input("What are your initials? ")
print(" ".join(user_input for _ in range(7)))
Output:
What are your initials? GIS GIS GIS GIS GIS GIS GIS GIS
(Sep-11-2021, 08:21 PM)perfringo Wrote: [ -> ]Is it Python 2?

You should think it through before starting to code. If you take input from user, then it could be one character or five or whatnot. This means that number of spaces depends from user input length. As of printing spaces - this can be done in similar fashion as with any other character.

Its Python 3.9
(Sep-11-2021, 08:27 PM)Yoriz Wrote: [ -> ]Using python 3
user_input = input("What are your initials? ")
print(" ".join(user_input for _ in range(7)))
Output:
What are your initials? GIS GIS GIS GIS GIS GIS GIS GIS

This is the output i am trying to get, please remember that the \\\ are meant to be blanks spaces

GIS GIS GIS GIS GIS GIS GIS
GIS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\GIS
GIS\\\\\\\\\\\\\\\GIS\\\\\\\\\\\\\\\\GIS
GIS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\GIS
GIS GIS GIS GIS GIS GIS GIS
(Sep-11-2021, 08:28 PM)pmorgan39339 Wrote: [ -> ]
(Sep-11-2021, 08:21 PM)perfringo Wrote: [ -> ]Is it Python 2?

Its Python 3.9

Have you tried to run your code then?

>>> x = raw_input ("What are your initials? ")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'raw_input' is not defined
>>> x = 'a'
>>> print x, x
  File "<stdin>", line 1
    print x, x
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(x, x)?
There are lots of ways to get this output. What have you tried? I know you did not try the code you provided because it would not run under Python3.9. I don't think it would run under Python 2.7

Python allows string concatenation using + and *. You might want to look at how that works.
(Sep-11-2021, 09:55 PM)deanhystad Wrote: [ -> ]There are lots of ways to get this output. What have you tried? I know you did not try the code you provided because it would not run under Python3.9. I don't think it would run under Python 2.7

Python allows string concatenation using + and *. You might want to look at how that works.

I did run that code and it will produce the first line and thats all it will do
Then you are running Python 2.7 or so. In Python 3 print went from a statement to a function(). You get a syntax error trying to run your program in Python 3.9.

How do you run your program? If you run it from the command line you might need to use python3 your/file/name.py instead of python your/file/name.py
(Sep-11-2021, 11:01 PM)pmorgan39339 Wrote: [ -> ]I did run that code and it will produce the first line and thats all it will do
You are using Python 2.7,run this and you will see the Path.
import sys

x = raw_input ("What are your initials? ")
print x , x , x , x , x , x , x,
print sys.executable
So you need to figure how to use Python 3.9 as Python 2.7 is dead💀
If need help with this post which OS you use, and eg other info like editor.
Pages: 1 2