Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 5th, 2012, 02:32 PM
Dimi56 Dimi56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 Dimi56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 32 sec
Reputation Power: 0
Unhappy Creating equilateral triangles with *'s using print function

Task

An equilateral triangle is one that has all three sides of equal length. Your task for this is to write a program that can print out equilateral triangles of different sizes. You will print them out using a '*' character and the Python "print" function, not with the graphics library.

Details

You should start by asking the user how big of a triangle they want.
To print the triangle, you should break it into lines.
Each line has some space at the start of it, then a number of * characters.
To make the triangles look more balanced, you should put a space between each *.
In order to make the print function not automatically move to the next line, you can pass end="" to it. For example the code print("*", end="") will print a * character. The next time you
print something, it will appear right after the *, not on the next line.
You can use recursion to solve this problem, but you don't have to.

Example Run
How big? 3
..*
.* *
* * *
(periods are there so it doesn't push the *'s to the left when i post)

I currently have a code (shown below) but it's only printing straight lines

x = int(input("Size of triangle:"))
space = " "
star = "*"
x = int(x)

for y in range(1, x + 1,1):
..for z in range(1, x - y + 1,1):
....space = space + ' ' #periods again for format
for z in range(1, 2 * y,1):
..star = star + "*"
print (space + star)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Creating equilateral triangles with *'s using print function

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap