0

Fix the code to output a triangle of Stars with four rows: print ("* ** *** ****")

This code tries to make a triangle out of stars. But oh no! There’s an error in there somewhere-it outputs all the stars on one line, instead of separate lines. Fix the code to output a triangle of stars that has 4 rows.

6th Aug 2022, 12:11 AM
Samuel Adesanya
2 Antworten
+ 2
s = "* ** *** ****".split() for st in s: print(st)
6th Aug 2022, 1:40 AM
SoloProg
SoloProg - avatar
+ 1
Samuel Adesanya the solution is to replace the spaces with the newline character. The simplest fix is to edit the string and type the metacharacter \n in place of the spaces. If you enjoy typing extra code, here are a couple more solutions: print(*"* ** *** ****".split(),sep='\n') print("* ** *** ****".replace(' ','\n')) If you dislike metacharacters, then you can use triple quotation: print("""* ** *** ****""")
7th Aug 2022, 8:14 PM
Brian
Brian - avatar