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 -
in
for
loop in second line , have missed closing bracket -for in range (len(str):
, should -for in range (len(str)):
there no
casting
in python, convert input string, have useint
function,int(...)
, line(int)(input(...))
should -int(input(...))
.in loop, defining index
i
, usingch
inside loop, should usingi
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
Post a Comment