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 February 14th, 2013, 11:49 AM
hannahcorbin1 hannahcorbin1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 hannahcorbin1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 43 sec
Reputation Power: 0
Help needed displaying a stair step pattern

Hi, This program works, but is slightly off. The output is coming out different than what I am trying to achieve. Any helpful suggestions? Thanks.

#this program displays a stair-step pattern.


num_steps = 6

for r in range(num_steps):
for c in range (r):
print(' ', end='')
print ('#')
print ('#')

Output from code above
>>>
#
#
_ #
___#
____#
#
___#
#
____#
#__
____ #
#
>>>
This is the pattern I am trying to get it to display. (where the underscores are should be black spaces.
##
#_#
# __#
#____ #
#______ #
#_______ #

Reply With Quote
  #2  
Old February 14th, 2013, 12:06 PM
rrashkin's Avatar
rrashkin rrashkin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Location: 39N 104.28W
Posts: 97 rrashkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 15 h 24 m 4 sec
Reputation Power: 2
I'm not all that familiar with Python 3 (which it seems you're using) but I think the problem is in the first of your 2 "print("#")"s. That is, the default is to add a linefeed so you should have "print("#", end="")" or whatever is the proper syntax.

Also, it helps if you use code tags and thus preserve the indentation (although in this case it's fairly transparent).

By the way, in Python 2.x, I'd do it like this (where "n" is your numsteps):
Code:
>>> for i in xrange(n):
...   print "#"+i*"_"+"#"
##
#_#
#__#
#___#
#____#
#_____#

Last edited by rrashkin : February 14th, 2013 at 12:15 PM. Reason: on second thought

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help needed displaying a stair step pattern

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