New to python and need help with spacing - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: New to python and need help with spacing (/thread-34885.html) Pages:
1
2
|
New to python and need help with spacing - pmorgan39339 - Sep-11-2021 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. RE: New to python and need help with spacing - perfringo - Sep-11-2021 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. RE: New to python and need help with spacing - Yoriz - Sep-11-2021 Using python 3 user_input = input("What are your initials? ") print(" ".join(user_input for _ in range(7)))
RE: New to python and need help with spacing - pmorgan39339 - Sep-11-2021 (Sep-11-2021, 08:21 PM)perfringo Wrote: Is it Python 2? Its Python 3.9 RE: New to python and need help with spacing - pmorgan39339 - Sep-11-2021 (Sep-11-2021, 08:27 PM)Yoriz Wrote: Using python 3 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 RE: New to python and need help with spacing - perfringo - Sep-11-2021 (Sep-11-2021, 08:28 PM)pmorgan39339 Wrote:(Sep-11-2021, 08:21 PM)perfringo Wrote: Is it Python 2? 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)? RE: New to python and need help with spacing - deanhystad - Sep-11-2021 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. RE: New to python and need help with spacing - pmorgan39339 - Sep-11-2021 (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 I did run that code and it will produce the first line and thats all it will do RE: New to python and need help with spacing - deanhystad - Sep-11-2021 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 RE: New to python and need help with spacing - snippsat - Sep-11-2021 (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 doYou 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.executableSo 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. |