Posts: 6
Threads: 3
Joined: May 2017
I need the triangle to be in reverse. The assignment requires a nested loop to generate a triangle with the user input of how many lines.
Currently, I get answers such as:
OOOO
OOO
OO
O
When I actually need it to be like this:
I just need to get it flipped-over on the other side.
base_size = int(input("How many lines? "))
columns = base_size
for row in range (base_size) :
for columns in range (columns) :
print('O', end='')
print()
Posts: 8,129
Threads: 159
Joined: Sep 2016
one option is to use string formatting and specify fill option.
another one is to print the space yourself
Posts: 3,458
Threads: 101
Joined: Sep 2016
The image is broken. What's the expected output?
Posts: 4,220
Threads: 97
Joined: Sep 2016
I think you want the first loop to be over range(base_size), and the second loop to be over range(rows). But as nilamo says, a better idea of the expected output would help.
Posts: 1,298
Threads: 38
Joined: Sep 2016
May-27-2017, 10:28 PM
(This post was last modified: May-27-2017, 10:28 PM by sparkz_alot.)
I think he's looking for
OOOO
OOO
OO
O maybe?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 3,458
Threads: 101
Joined: Sep 2016
They mentioned reversed, but I didn't know if that's horizontal or vertically reversed.
Posts: 8,129
Threads: 159
Joined: Sep 2016
Yes, that's what he wants. I have no problem to see the picture. Actually I don't even realised it is an image.
Posts: 1,298
Threads: 38
Joined: Sep 2016
If I click on the image link, I get a University's login page
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 6
Threads: 3
Joined: May 2017
May-28-2017, 06:01 PM
(This post was last modified: May-28-2017, 06:10 PM by Babbare.)
Sorry guys, you're all correct. The imagine is reverse from what I need, so the code has to be just starting on the opposite side.
(May-26-2017, 09:21 PM)ichabod801 Wrote: I think you want the first loop to be over range(base_size), and the second loop to be over range(rows). But as nilamo says, a better idea of the expected output would help. Yes, you're correct. This is exactly what I am looking for,
(May-27-2017, 10:28 PM)sparkz_alot Wrote: I think he's looking for OOOO OOO OO O maybe? Yes, sorry. It's like this:
It starts from like the right side and then stacks each new line from right to left instead of left to right.
Example:
four lines to start
then three lines from right to left
two lines from right to left
and then the last line.
It will use all '0,' so each line from right to left will be 'O'.
Posts: 8,129
Threads: 159
Joined: Sep 2016
May-28-2017, 07:25 PM
(This post was last modified: May-28-2017, 07:25 PM by buran.)
so what you have tried, based on my suggestion in post #2?
If you expect someone to do this for you - you are mistaken.
some examples
n=7
x=4
# example 1
print('{: >{width}s}'.format('O'*x, width=n))
# example 2
print('{}{}'.format(' '*(n-x),'O'*x))
# example 3
print(' '*(n-x), end='')
print('O'*x, end='')
print() the last one, which is the worst one can be done with even more loops
output
Output: OOOO
OOOO
OOOO
Now it's up to you to wrap one of these in a loop
|