1
name=input("Enter your name: ")
message=input("Enter your message:")
namefinal=list(name)

for namefinal in message:
     del(namefinal)
     print(message)

I need help with creating a program that gets a message from the user and removes all of the letters that are in the user’s name. I made the user input(name) into a list but I don't know how to delete the letters. For example if I type in Charan and the message is Lebron James it will delete r,a,and n from Lebron James, making it Lebo Jmes.

2
  • Please add your own logic attempt in the code snippet. Commented Oct 10, 2015 at 2:18
  • Welcome to Stack Overflow. I have reformatted your title. Please provide the code you have attempted in the future. It helps others to help you faster. Commented Oct 12, 2015 at 8:07

2 Answers 2

1

you can do like this:

name=input("Enter your name: ")
message=input("Enter your message:")
namefinal = ''
for letter  in name:   
   if letter not in message:
       namefinal += letter
print namefinal
Sign up to request clarification or add additional context in comments.

3 Comments

can u tell me what for loop does
lik explain each line in the for loop
for loop of line 4 iterates each letter in name string,and then verify if the letter is not in message
0

You can use replace, to remove letters:

for letter in name:
    message = message.replace(letter, '')

Comments

Your Answer

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