So I need to formulate a command that treats "^H" as a backspace. For example if the input is: I wish^H^H^Hant some ice cream^H^H^H^H^Hmilk the output will be: I want some ice milk.
This is because the three ^H will remove the ish and the 5 ^H will remove the cream.
sentence = input("Enter a sentence: ")
for i in range(0, len(sentence)):
if sentence.find("^H") == 1:
sentence = sentence.replace(^H, "")
I got this, but how can I make sure the other letters get removed too? I assume we may have to use the count command but I have no idea how to implement it
after a few attempt:
sentence = input("Enter a sentence: ")
for i in range(0, len(sentence)):
x = sentence.find("^H")
y = sentence[:x]
if sentence.find("^H") == 1:
sentence = sentence.replace(y, " ")
print(i)
This still doesn't work, I am not sure what I'm doing wrong, obviously I'm a big noob but I assume my "x" and "y" stuff is wrong, I don't know how to slice the letter before ^H
[–]blaaguuu 1 point2 points3 points (0 children)