0

wow it's me again!

i have:

i=0
while i<11:
        print i,
        print ''
        i=i+1

this gives the answer:
0
1
2
3
4
5
6
7
8
9
10

i need to give the answer.

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *

i know my code has print i which is only temporary and it should be print *.
Is there any command that can do someting like:

For amount in i:
print '*'

specifically whatever integer is in i to print that many '*'s

i know of

for i in range(10)

but i must keep this in while and cant use for.


i understand this is long and i appreciate your patience thanks.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by thehivetyrant
1

replace print i with print "*" * i . You may need to initialize i to 1 instead of 0.

EDIT:

Actually, that's the easy way out. The other way which might be the one your tutor is looking for (since this seems like homework) is to create another loop inside that loops i times, printing "*" on each iteration. Hint: use print "*", instead of print "*" to get the next "*" you print to stay on the same line.

Votes + Comments
smart help
0

ahh yes that seems so simple i've done times i and such before i dont know why i didint think of it.

Yeah that could be the easy way out. But i have to admit that is what i would have done (since that was where i was heading weith my code)

Haha yur just a guessing machine, yes it is homework from tutor =)

and the for loop i am changing from does have a 2nd loop that loops '*'s. So i probably should do as you said and do a 2nd loop.

the for loop i am converting from does use a '*', but i just assumed the , was just instead of ;

guess not.

thanks i'll give the harder one a go, haha and your always helping me, your like my pocket helper. and i thank you for it ^^

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.