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 29th, 2012, 08:58 AM
brod615 brod615 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 6 brod615 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 52 sec
Reputation Power: 0
Printing multiple lines in a user input range?

I need help with programming something in python

I need to take the users input on how many lines to print of x, then print that line and all lines prior

For example if the user in puts 7 lines, I need the program to evaluate

x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxx

I have tried using the current code with a for loop and a range, but am still having problems, can anyone point me in the right direction?

def main():
n = input("How many lines would you like to print?"
for n in range (0,100)
print: "x" * n

I was thinking this would work, but I keep on getting an error in regards to the print portion. Anyone know where I am going wrong?

Reply With Quote
  #2  
Old November 29th, 2012, 09:52 AM
rrashkin's Avatar
rrashkin rrashkin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Location: 39N 104.28W
Posts: 90 rrashkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 41 m 29 sec
Reputation Power: 2
Quote:
Originally Posted by brod615
I need help with programming something in python

I need to take the users input on how many lines to print of x, then print that line and all lines prior

For example if the user in puts 7 lines, I need the program to evaluate

x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxx

I have tried using the current code with a for loop and a range, but am still having problems, can anyone point me in the right direction?

def main():
n = input("How many lines would you like to print?"
for n in range (0,100)
print: "x" * n

I was thinking this would work, but I keep on getting an error in regards to the print portion. Anyone know where I am going wrong?


The print statement (or function in v3.x) doesn't take ":"s.

Code:
>>> n=int(raw_input('number of lines '))
number of lines 8
>>> for i in xrange(n): print i*'x'
...

x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxxx
>>>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Printing multiple lines in a user input range?

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