0

How can i make this code break when it reaches 50 stars?

https://code.sololearn.com/cw00btLXBzgt/?ref=app

24th Nov 2018, 12:13 PM
David Arumba
David Arumba - avatar
6 ответов
+ 4
In Python syntax what Dominique said could be coded as j = "*" for i in range(1, 51): print(j * i) Note: range(1, 51) makes i range over the integers 1 to 50. j * i produces the string formed by j concatenated with itself i times. For example since j="*", j*3 is "***". But if you don't want to change your original code too much, you could also do j = "*" while True: print(j) j += "*" if len(j) > 50: break The effect is the same, of course.
24th Nov 2018, 1:24 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Davido ArumbaTheemperor no idea why i thought it was java xD anw thanks Kishalaya Saha
25th Nov 2018, 11:40 AM
Dominique Abou Samah
Dominique Abou Samah - avatar
+ 1
You need a variable as a counter for it Either with a while loop: Int a = 0; String j = "*"; While(a<50){ j += "*"; Print (j); a++; } Or use a for loop String j = "*"; For(int i = 0; i<50; i++){ j += "*"; Print(j); }
24th Nov 2018, 12:18 PM
Dominique Abou Samah
Dominique Abou Samah - avatar
+ 1
Davido ArumbaTheemperor , you're welcome! 😊
25th Nov 2018, 3:22 AM
Kishalaya Saha
Kishalaya Saha - avatar
24th Nov 2018, 6:57 PM
David Arumba
David Arumba - avatar
0
Kishalaya Saha thanks, this helped
24th Nov 2018, 6:57 PM
David Arumba
David Arumba - avatar