python - How to print output of for loop on same line -


here code:

def missing_ch(number, string):       in range(len(string)):         if i==number:            continue         else:               print(string[i], end=' ')       return string='hello' num=int(input("enter position of char")) missing_ch(num, string) 

how output characters printed in same line?

i see 3 issues in program -

  1. in for loop in second line , have missed closing bracket - for in range (len(str): , should - for in range (len(str)):

  2. there no casting in python, convert input string, have use int function, int(...) , line (int)(input(...)) should - int(input(...)) .

  3. in loop, defining index i, using ch inside loop, should using i instead of `ch.

example -

    in range (len(str):         if(i==num):             continue         print(str[i],end=' ')     return 

the print statement print items without appending newline fine, should working.

a working example -

>>> def foo(): ...     print("hello",end=" ") ...     print("middle",end=" ") ...     print("bye") ... >>> foo() hello middle bye 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -