0

Printing the output tab separated..

I have a program where my ouput should be tab separated.ie The function should take one parameter that represents the number of 'steps' to print. It should then return a string that, when printed, shows output like the following: #print(steps(3)) 111 222 333 #print(steps(6)) 111 222 333 444 555 666 THis is the code I have written: def steps(no_steps): j = 0 for i in range(1, no_steps+1): print(("\t" * j) + (str(i) * 3) + "\n") j+=1 return '' print(steps(3)) print(steps(6)) BUt the output shows error as follow, We tested your code with num_steps = 3. We expected steps to return the str "111 222 333 ". However, it returned the str "". Please help, thanks.

20th Sep 2020, 11:47 AM
NG_
NG_ - avatar
2 Antworten
0
check your steps function its returning empty string " something like this? def steps(no_steps): st = '' j = 0 for i in range(0, no_steps): st += (("\t" * 2*(i+j)) + (str(i+1) * 3) + '\n') j+=1 return st print(steps(3)) print(steps(6))
20th Sep 2020, 11:58 AM
minirkk
minirkk - avatar
0
Thank you so much. It works now..
20th Sep 2020, 12:19 PM
NG_
NG_ - avatar