0
How can i make this code break when it reaches 50 stars?
6 Respuestas
+ 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.
+ 2
Davido ArumbaTheemperor no idea why i thought it was java xD anw thanks Kishalaya Saha
+ 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);
}
+ 1
Davido ArumbaTheemperor , you're welcome! 😊
0
Dominique Abou Samah python syntax please
0
Kishalaya Saha thanks, this helped