+ 1

Printing string every new line one more character

Hi, few days ago i have seen web code here and i thought do this in Python. So wrote this but I think this code could look nicer. What are your suggestions? w = 'guest' for char in range(1,2): print("\n",w[0],"\n",w[0]+w[1],"\n",w[0]+w[1]+w[2],"\n",w[0]+w[1]+w[2]+w[3],"\n",w[0]+w[1]+w[2]+w[3]+w[4])

13th Jan 2017, 4:26 PM
guest013
guest013 - avatar
2 Respuestas
+ 2
char='guest' print('\n'.join(char[:k] for k in range(1,len(char)+1)))
13th Jan 2017, 9:07 PM
Sai Kiran Rayapureddy
Sai Kiran Rayapureddy - avatar
0
@Sai Kiran Havent thought about using new line in join. Thanks for tip ;)
13th Jan 2017, 9:11 PM
guest013
guest013 - avatar