+ 3

How do I print each iteration with a input into 1 string?

https://code.sololearn.com/c9dNuQ9SYV4x/#py I am having a hard time trying to figure out how to print each iteration and each str(input) into 1 str. I need to return 1 string not each iteration. Help..

29th Jul 2022, 1:09 PM
Esther McAngus
7 odpowiedzi
+ 4
As suggested by jayakrishna and Lothar, > remove the line 20 > replace line 19 with: print(f"{x} {word}", end=" ") - line 20 has return keyword, whenever python encounters the return keyword, it exits the function and provides everything written after the 'return' to caller. - In line 19 when you are printing the output, 'print()' function automatically adds a new line. By providing 'end' in print function argument, you are telling print() function not to add newline but to add a space instead (or whatever specified in 'end') You can replace it with anything you want: For example: print(f"{x} {word}", end="-") If you do this, you output will be separated by a dash ('-')
29th Jul 2022, 5:50 PM
Sandeep
Sandeep - avatar
+ 5
Esther McAngus , the output with print() function should overwrite the "\n" (new-line sequence) with 1 space " " !!! print(f"{x} {word}",end=" ") since your output is given from the function print_ten(), we don't need to return anything to the caller. remove this line
29th Jul 2022, 5:18 PM
Lothar
Lothar - avatar
+ 3
Can you complete the code for what you getting?.. print( "text", end="") #end="" Overrites \n printing character at end so it will remain in same line..
29th Jul 2022, 1:21 PM
Jayakrishna 🇮🇳
+ 2
Thank u all I love our community!
29th Jul 2022, 6:06 PM
Esther McAngus
+ 2
ten=[] def print_ten(word): x = 0 for i in range(1,10): x=i w = word ten.append(f'{x} {w}') print(' '.join(ten)) print_ten('hey') Try this one i guess it’s gonna work..
31st Jul 2022, 8:28 AM
Sara Shalmi
+ 1
It may be.. y=input() def print_ten(word): x = 0 while x <= 10: x += 1 print(x,str(y)) print_ten(y)
30th Jul 2022, 9:31 PM
Rjdp😉
Rjdp😉 - avatar
0
Thank u again! I will definitely give them all a try!
31st Jul 2022, 1:14 PM
Esther McAngus