+ 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])
2 Réponses
+ 2
char='guest'
print('\n'.join(char[:k] for k in range(1,len(char)+1)))
0
@Sai Kiran Havent thought about using new line in join. Thanks for tip ;)