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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -