Hi I was making a code that turns input into a way that it seemed as if you were talking like a snake(IDK I was bored) and in the while loop it seems to print extra blank lines, how can I change my code to remove those extra lines?. my code:
line = input("Line: ")
while line != "":
line = input("Line: ")
line = line.replace('s','sss')
line = line.replace('S','Sss')
print(line)
desired output(my output is that same except after 3rd 'Line: ' I have a blank line below(SO didn't allow my blank line as valid code)):
Line: Say, what sound does a snake make?
Sssay, what sssound doesss a sssnake make?
Line: Hiss
Hissssss
Line:
It looks like what you meant is this:
line = input("Line: ")
while line:
line = line.replace('s','sss')
line = line.replace('S','Sss')
print(line)
line = input("Line: ")
So the print
is inside the loop, and it inputs a new line at the end of your loop, right before the while
condition checks if it is empty.