hi
Does any one know how to print a row of stars like *****
****
***
using python. i can do it in c but not inpython
pythonpython programming
Page 1 of 1
6 Replies - 1304 Views - Last Post: 07 December 2009 - 05:11 PM
Replies To: python
#2
Re: python
Posted 30 November 2009 - 06:02 AM
aus001, on 30 Nov, 2009 - 04:56 AM, said:
hi
Does any one know how to print a row of stars like *****
****
***
using python. i can do it in c but not inpython
Does any one know how to print a row of stars like *****
****
***
using python. i can do it in c but not inpython
If you know how to do it in C, then it's a matter of adapting the syntax to Python.
Here is a hint: http://ibiblio.org/g...d/for-loop.html.
#3
Re: python
Posted 05 December 2009 - 09:46 AM
# For loop i from 5 to 0, subtracting 1 each time
for i in range(5, 0, -1):
print '*' * i
This post has been edited by programble: 05 December 2009 - 09:47 AM
#4
Re: python
Posted 05 December 2009 - 02:30 PM
print "\n".join([(5-i) * "*" for i in range(3)])
#5
Re: python
Posted 06 December 2009 - 09:59 AM
You can also use string formatting:
which will output:
*****
*****
*****
str.format is extremely useful, please look to your resourses to learn it ! (including python.org)
for _ in range(3):
print "{0:<5}".format("*")
which will output:
*****
*****
*****
str.format is extremely useful, please look to your resourses to learn it ! (including python.org)
#6
Re: python
Posted 07 December 2009 - 12:17 AM
You could also just use the three quotes style to get a particular format:
That's just if you want to print it once or so.
print """ ******* ******* ******* ******* """
That's just if you want to print it once or so.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|