- #1
shivajikobardan
- 674
- 54
Thread moved from the technical forums to the schoolwork forums
Summary:: confused in program.
Write a while loop to display each character from a string and if a character is a space, then don’t display it and move to the next character.
Use the if condition with the continue statement to jump to the next iteration. If the current character is space, then the condition evaluates to true, then the continue statement will execute, and the loop will move to the next iteration by skipping the remeaning body.
what is this program supposed to do can you explain a bit about that?
Here is what it is doing. But it is very unclear to me what are we trying to do.It doesn't make any sense. IMO what it means is to not display spaces but display other alphabets. SO I wrote a code-:but this code doesn't work properly as I would like it to work. It gives error at last after doing everything right.
Enter a string-: Joe Biden
Output-: JoeBiden
Which I believe is correct what I want in that above program.
But here is an error that is ruining my mood.
File "E:\Udemy My Courses\LoopsTutorials\main.py", line 6, in <module>
if (word.isspace()):
IndexError: string index out of range
Write a while loop to display each character from a string and if a character is a space, then don’t display it and move to the next character.
Use the if condition with the continue statement to jump to the next iteration. If the current character is space, then the condition evaluates to true, then the continue statement will execute, and the loop will move to the next iteration by skipping the remeaning body.
what is this program supposed to do can you explain a bit about that?
Here is what it is doing. But it is very unclear to me what are we trying to do.It doesn't make any sense. IMO what it means is to not display spaces but display other alphabets. SO I wrote a code-:but this code doesn't work properly as I would like it to work. It gives error at last after doing everything right.
Python:
word=input("Enter a string")
i=-1
while(i<=len(word)):
i =i+ 1
if (word[i].isspace()):
continue
print(word[i],end="")
Enter a string-: Joe Biden
Output-: JoeBiden
Which I believe is correct what I want in that above program.
But here is an error that is ruining my mood.
File "E:\Udemy My Courses\LoopsTutorials\main.py", line 6, in <module>
if (word.isspace()):
IndexError: string index out of range
Last edited by a moderator: