python printing clipped squaresHow can I represent an 'Enum' in Python?How to flush output of print function?Syntax error on print with Python 3Should I put #! (shebang) in Python scripts, and what form should it take?Way to create multiline comments in Python?What is the Python 3 equivalent of “python -m SimpleHTTPServer”Print multiple arguments in PythonUsing Python 3 in virtualenvWhat does “SyntaxError: Missing parentheses in call to 'print'” mean in Python?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
Did Pope Urban II issue the papal bull "terra nullius" in 1095?
Do you "gain" 1st level?
K-Type Thermocouple, Instrumentation Op-Amp and Arduino
What is the farthest a camera can see?
If a person claims to know anything could it be disproven by saying 'prove that we are not in a simulation'?
Why aren't rainbows blurred-out into nothing after they are produced?
Help, I cannot decide when to start the story
graphs in latex
What is the prop for Thor's hammer made of?
Sum Square Difference, which way is more Pythonic?
How much can I judge a company based on a phone screening?
Shifting tenses in the middle of narration
Is it possible to know the exact chord from the roman numerals
Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?
Units of measurement, especially length, when body parts vary in size among races
Is there a way to proportionalize fixed costs in a MILP?
How do I call a 6-digit Australian phone number with a US-based mobile phone?
Good textbook for queueing theory and performance modeling
Scam? Phone call from "Department of Social Security" asking me to call back
Does fossil fuels use since 1990 account for half of all the fossil fuels used in history?
What should we do with manuals from the 80s?
Random Stripe Webhook Issues
Bringing Power Supplies on Plane?
Should I leave building the database for the end?
python printing clipped squares
How can I represent an 'Enum' in Python?How to flush output of print function?Syntax error on print with Python 3Should I put #! (shebang) in Python scripts, and what form should it take?Way to create multiline comments in Python?What is the Python 3 equivalent of “python -m SimpleHTTPServer”Print multiple arguments in PythonUsing Python 3 in virtualenvWhat does “SyntaxError: Missing parentheses in call to 'print'” mean in Python?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
the python code is printing this
___
____
____
____
_
instead of this
____
____
____
____
this is the code some of it doesn't do anything because it has been commented out so just ignore the associated variables
X = 0 #majic number
L = 0 #lines
i = 0 #list intilising varble thing
x = 175 #cordinates are x and y
y = 0 #dont set x&y above 175
Del = x + 1
X = y*176
x = x+X
stuff = []
for L in range(0,7):
for i in range(0,7):
i + 1
stuff.insert(i,"_")
stuff.insert(i,"n")
i + 1
'''stuff.pop(Del)
stuff.insert(x,"q")'''
print(*stuff, sep='')
in the current settings it supposed to print a 8*8 board. i have fiddled around with the position of the i + 1 but it didn't seem to make a difference.
if someone knows how to get in a alternating pattern that would be great.
when i did that i just got abbbbaaa. i should of mentioned this early but the end goal is to create a game of chess in the terminal.
python-3.x
add a comment |
the python code is printing this
___
____
____
____
_
instead of this
____
____
____
____
this is the code some of it doesn't do anything because it has been commented out so just ignore the associated variables
X = 0 #majic number
L = 0 #lines
i = 0 #list intilising varble thing
x = 175 #cordinates are x and y
y = 0 #dont set x&y above 175
Del = x + 1
X = y*176
x = x+X
stuff = []
for L in range(0,7):
for i in range(0,7):
i + 1
stuff.insert(i,"_")
stuff.insert(i,"n")
i + 1
'''stuff.pop(Del)
stuff.insert(x,"q")'''
print(*stuff, sep='')
in the current settings it supposed to print a 8*8 board. i have fiddled around with the position of the i + 1 but it didn't seem to make a difference.
if someone knows how to get in a alternating pattern that would be great.
when i did that i just got abbbbaaa. i should of mentioned this early but the end goal is to create a game of chess in the terminal.
python-3.x
add a comment |
the python code is printing this
___
____
____
____
_
instead of this
____
____
____
____
this is the code some of it doesn't do anything because it has been commented out so just ignore the associated variables
X = 0 #majic number
L = 0 #lines
i = 0 #list intilising varble thing
x = 175 #cordinates are x and y
y = 0 #dont set x&y above 175
Del = x + 1
X = y*176
x = x+X
stuff = []
for L in range(0,7):
for i in range(0,7):
i + 1
stuff.insert(i,"_")
stuff.insert(i,"n")
i + 1
'''stuff.pop(Del)
stuff.insert(x,"q")'''
print(*stuff, sep='')
in the current settings it supposed to print a 8*8 board. i have fiddled around with the position of the i + 1 but it didn't seem to make a difference.
if someone knows how to get in a alternating pattern that would be great.
when i did that i just got abbbbaaa. i should of mentioned this early but the end goal is to create a game of chess in the terminal.
python-3.x
the python code is printing this
___
____
____
____
_
instead of this
____
____
____
____
this is the code some of it doesn't do anything because it has been commented out so just ignore the associated variables
X = 0 #majic number
L = 0 #lines
i = 0 #list intilising varble thing
x = 175 #cordinates are x and y
y = 0 #dont set x&y above 175
Del = x + 1
X = y*176
x = x+X
stuff = []
for L in range(0,7):
for i in range(0,7):
i + 1
stuff.insert(i,"_")
stuff.insert(i,"n")
i + 1
'''stuff.pop(Del)
stuff.insert(x,"q")'''
print(*stuff, sep='')
in the current settings it supposed to print a 8*8 board. i have fiddled around with the position of the i + 1 but it didn't seem to make a difference.
if someone knows how to get in a alternating pattern that would be great.
when i did that i just got abbbbaaa. i should of mentioned this early but the end goal is to create a game of chess in the terminal.
python-3.x
python-3.x
edited Mar 27 at 11:21
Snowball
asked Mar 27 at 9:59
SnowballSnowball
63 bronze badges
63 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Just use the increminting operator '+='. i + 1 means nothing in your code and wont have any effect if you removed it. It should be as follows:
for L in range(0,7):
for i in range(0,7):
i += 1
stuff.insert(i,"_")
stuff.insert(i,"n")
add a comment |
for
works very differently in Python than it does in, say, C.
Also, in Python, you only very rarely need to use indices, especially since using iterators is more efficient.
I think you were trying to achieve this with your example:
#!/usr/bin/env python3
x = 3
y = 2
stuff = []
for L in range(y):
for i in range(x):
stuff.append('_')
stuff.append('n')
# the list now looks like this:
# stuff = ['_', '_', '_', 'n', '_', '_', '_', 'n']
# It contains y*x strings, each length 1.
# This is something like "char **stuff" in C.
output = ''.join(stuff) # this creates '___n___n'
print(output)
Note that the variables i
and L
are actually never used, we are just using the number of items represented by each range
to iterate over.
Or if you don't care about the strings being stored in a list and just want to print the rectangle:
#!/usr/bin/env python3
x = 3
y = 2
for L in range(y):
print('_' * x) # by default, print appends 'n' to the end.
'_' * x
just repeats the string '_'
x
times, creating another string, '___'
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374408%2fpython-printing-clipped-squares%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just use the increminting operator '+='. i + 1 means nothing in your code and wont have any effect if you removed it. It should be as follows:
for L in range(0,7):
for i in range(0,7):
i += 1
stuff.insert(i,"_")
stuff.insert(i,"n")
add a comment |
Just use the increminting operator '+='. i + 1 means nothing in your code and wont have any effect if you removed it. It should be as follows:
for L in range(0,7):
for i in range(0,7):
i += 1
stuff.insert(i,"_")
stuff.insert(i,"n")
add a comment |
Just use the increminting operator '+='. i + 1 means nothing in your code and wont have any effect if you removed it. It should be as follows:
for L in range(0,7):
for i in range(0,7):
i += 1
stuff.insert(i,"_")
stuff.insert(i,"n")
Just use the increminting operator '+='. i + 1 means nothing in your code and wont have any effect if you removed it. It should be as follows:
for L in range(0,7):
for i in range(0,7):
i += 1
stuff.insert(i,"_")
stuff.insert(i,"n")
answered Mar 27 at 11:34
Ahmed HawaryAhmed Hawary
1119 bronze badges
1119 bronze badges
add a comment |
add a comment |
for
works very differently in Python than it does in, say, C.
Also, in Python, you only very rarely need to use indices, especially since using iterators is more efficient.
I think you were trying to achieve this with your example:
#!/usr/bin/env python3
x = 3
y = 2
stuff = []
for L in range(y):
for i in range(x):
stuff.append('_')
stuff.append('n')
# the list now looks like this:
# stuff = ['_', '_', '_', 'n', '_', '_', '_', 'n']
# It contains y*x strings, each length 1.
# This is something like "char **stuff" in C.
output = ''.join(stuff) # this creates '___n___n'
print(output)
Note that the variables i
and L
are actually never used, we are just using the number of items represented by each range
to iterate over.
Or if you don't care about the strings being stored in a list and just want to print the rectangle:
#!/usr/bin/env python3
x = 3
y = 2
for L in range(y):
print('_' * x) # by default, print appends 'n' to the end.
'_' * x
just repeats the string '_'
x
times, creating another string, '___'
add a comment |
for
works very differently in Python than it does in, say, C.
Also, in Python, you only very rarely need to use indices, especially since using iterators is more efficient.
I think you were trying to achieve this with your example:
#!/usr/bin/env python3
x = 3
y = 2
stuff = []
for L in range(y):
for i in range(x):
stuff.append('_')
stuff.append('n')
# the list now looks like this:
# stuff = ['_', '_', '_', 'n', '_', '_', '_', 'n']
# It contains y*x strings, each length 1.
# This is something like "char **stuff" in C.
output = ''.join(stuff) # this creates '___n___n'
print(output)
Note that the variables i
and L
are actually never used, we are just using the number of items represented by each range
to iterate over.
Or if you don't care about the strings being stored in a list and just want to print the rectangle:
#!/usr/bin/env python3
x = 3
y = 2
for L in range(y):
print('_' * x) # by default, print appends 'n' to the end.
'_' * x
just repeats the string '_'
x
times, creating another string, '___'
add a comment |
for
works very differently in Python than it does in, say, C.
Also, in Python, you only very rarely need to use indices, especially since using iterators is more efficient.
I think you were trying to achieve this with your example:
#!/usr/bin/env python3
x = 3
y = 2
stuff = []
for L in range(y):
for i in range(x):
stuff.append('_')
stuff.append('n')
# the list now looks like this:
# stuff = ['_', '_', '_', 'n', '_', '_', '_', 'n']
# It contains y*x strings, each length 1.
# This is something like "char **stuff" in C.
output = ''.join(stuff) # this creates '___n___n'
print(output)
Note that the variables i
and L
are actually never used, we are just using the number of items represented by each range
to iterate over.
Or if you don't care about the strings being stored in a list and just want to print the rectangle:
#!/usr/bin/env python3
x = 3
y = 2
for L in range(y):
print('_' * x) # by default, print appends 'n' to the end.
'_' * x
just repeats the string '_'
x
times, creating another string, '___'
for
works very differently in Python than it does in, say, C.
Also, in Python, you only very rarely need to use indices, especially since using iterators is more efficient.
I think you were trying to achieve this with your example:
#!/usr/bin/env python3
x = 3
y = 2
stuff = []
for L in range(y):
for i in range(x):
stuff.append('_')
stuff.append('n')
# the list now looks like this:
# stuff = ['_', '_', '_', 'n', '_', '_', '_', 'n']
# It contains y*x strings, each length 1.
# This is something like "char **stuff" in C.
output = ''.join(stuff) # this creates '___n___n'
print(output)
Note that the variables i
and L
are actually never used, we are just using the number of items represented by each range
to iterate over.
Or if you don't care about the strings being stored in a list and just want to print the rectangle:
#!/usr/bin/env python3
x = 3
y = 2
for L in range(y):
print('_' * x) # by default, print appends 'n' to the end.
'_' * x
just repeats the string '_'
x
times, creating another string, '___'
edited Mar 27 at 12:51
answered Mar 27 at 12:38
mossymountainmossymountain
1036 bronze badges
1036 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374408%2fpython-printing-clipped-squares%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown