0

The purpose of my program is to ask a user to input a sentence , then the user is asked to input any amount of characters they would like removed from the string. the program only replaces the last character to be input , not all of them

please keep in mind I'm fairly new at this :)

print("Please enter a sentence")



sentence = input()



print("Please type the  characters you would like to make dissapear!!! ")


while True:
    repchar = input()

    for i in repchar:
    
        i = sentence.replace(repchar , "")

    if repchar == "":
        print(i)
        break

1 Answer 1

1

It was a minor error. You needed to make changes to the whole sentence, but since i changes in every iteration, the replaced sentence was never stored.

print("Please enter a sentence")
sentence = input()
print("Please type the  characters you would like to make dissapear!!! ")
while True:
    repchar = input()

    for i in repchar:
    
        sentence = sentence.replace(repchar , "") # here you were replacing the 
                                                  # character but storing it in i 
                                                  # that changes every iteration

    if repchar == "":
        print(sentence) # Printing the sentence not just i
        break
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.