7 Replies - 5814 Views - Last Post: 27 March 2014 - 10:26 AM Rate Topic: -----

#1 kktong   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 14

How to print a left triangle..

Posted 27 March 2014 - 09:38 AM

So I'm new to Python and feel I don't have the best teacher in the world but that's besides the point I need help with my code.
So the first assignment I did it perfectly fine the goal was to print a right triangle to look like this:

T
T T
T T T
T T T T
T T T T T
T T T T T T
T T T T T T T

and this is the code I used to get that:

size = 7
letter = "T "
for i in range (1, size+1):
print letter * i 


And it printed just fine the way it was supposed to but now the next one is supposed to print out like so:

T
T T
T T T
T T T T
T T T T T
T T T T T T
T T T T T T T


I know what I did was just a fairly simple loop but now I don't know how to get it in reverse I have tried different things but nothing has printed out, it's just blank. And I'm only supposed to use for loops. And I've searched for ways to do it but everything I've found is for an upside down triangle which is not what I'm asked for.

Is This A Good Question/Topic? 0
  • +

Replies To: How to print a left triangle..

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14427
  • View blog
  • Posts: 57,841
  • Joined: 12-June 08

Re: How to print a left triangle..

Posted 27 March 2014 - 09:42 AM

Since the spaces are what makes this triangle a 'right' one versus a 'left'.. perhaps.. in your for-loop you keep an eye on how many spaces you need. It looks like each line going down there is one less space from a fixed size.
Was This Post Helpful? 0
  • +
  • -

#3 MentalFloss   User is online

  • .
  • member icon

Reputation: 584
  • View blog
  • Posts: 1,530
  • Joined: 02-September 09

Re: How to print a left triangle..

Posted 27 March 2014 - 09:43 AM

Start with just printing a column of right sided Ts

Can you accomplish that?

edit:
I cannot make the visual aid.

This post has been edited by MentalFloss: 27 March 2014 - 09:44 AM

Was This Post Helpful? 0
  • +
  • -

#4 kktong   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 14

Re: How to print a left triangle..

Posted 27 March 2014 - 09:56 AM

No I can't but I was just playing with the string formatting can I accomplish my goal with something like this?:

print "%013s" % "T"
            T

Was This Post Helpful? 0
  • +
  • -

#5 kktong   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 14

Re: How to print a left triangle..

Posted 27 March 2014 - 10:07 AM

I'm just helpless! And I don't get this! :(
Was This Post Helpful? 0
  • +
  • -

#6 MentalFloss   User is online

  • .
  • member icon

Reputation: 584
  • View blog
  • Posts: 1,530
  • Joined: 02-September 09

Re: How to print a left triangle..

Posted 27 March 2014 - 10:08 AM

Try it and see. Manually use that statement to see if you can get some of what a loop would do. What has to change for each iteration?

For example, with the initial problem, a manual check would be like this:

letter = 'T'
print(letter * 0)
print(letter * 1)
print(letter * 2)
print(letter * 3)
print(letter * 4)
print(letter * 5)
print(letter * 6)



You say to yourself, "Oh it increments each step and it starts at 1 because zero prints nothing and that's not requirements. So, I'll use a for loop and start at 1."

But this is obvious to you now because you solved that one.

Just do these steps for your new problem. How do you solve it manually? Then make it auto complete with a loop.

This post has been edited by MentalFloss: 27 March 2014 - 10:12 AM

Was This Post Helpful? 1
  • +
  • -

#7 kktong   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 14

Re: How to print a left triangle..

Posted 27 March 2014 - 10:12 AM

It just has to look like the first triangle but flipped on it's hypotenuse.

Has spaces in between each character and grows larger from the right rather than the left. I've read everything in the chapter and nothing has helped.
Was This Post Helpful? 0
  • +
  • -

#8 MentalFloss   User is online

  • .
  • member icon

Reputation: 584
  • View blog
  • Posts: 1,530
  • Joined: 02-September 09

Re: How to print a left triangle..

Posted 27 March 2014 - 10:26 AM

I assure you that you have everything you need. You have knowledge of for loop and you have print statements and knowledge of multiplying output by some number to get that length of output of that character.

Stop googling this problem and try to work it out.

This problem isn't easy (obviously because you are struggling) so don't misunderstand me when I say it is basic. By that I mean, don't skimp on the fundamentals here. You have got to learn how to understand what is going on.

I will help you again ok?

letter = 'T'
space  = ' '
print(space * 6 + letter * 1)
print(space * 5 + letter * 2)



Now make it into a loop. I know you can solve this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1