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.
2 Réponses
+ 2
s = "* ** *** ****".split()
for st in s: print(st)
+ 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("""*
**
***
****""")