nested loops

K. Elo maillists at nic.fi
Wed Feb 27 02:02:21 EST 2013


Hi!

 > leonardo <tampucciolina at libero.it> writes:
>
>> how can i have it print  a row of stars beside each number, like this?:
>>
>> how many seconds?: 5
>> 5 * * * * *
>> 4 * * * *
>> 3 * * *
>> 2 * *
>> 1 *
>> blast off!

--- snip ---
sec = int(input("How many seconds? "))
for i in range(0,sec):
	print str(sec-i)+":"+" *"*(sec-i)
print "blast off!"
--- snip ---

Please note: the value for the upper bound is not included in the range. 
In my example, the actual range is from 0 to 4.

HTH,
Kimmo





More information about the Python-list mailing list