+ 1
How to find a word in a string
This is what I have tried but it's not executing as expected Name = input("Enter a string") Letter = input("Enter a letter") Repl = ("Enter a replacement") if (Name.find(Letter)==-1): print("Sorry the letter can not be found") else: print(Name.replace(Letter,Repl))
3 RĂ©ponses
+ 6
There is 1 issue in the code, see my comments:
Name = input("Enter a string")
Letter = input("Enter a letter")
Repl = input("Enter a replacement") # input missing
if Letter not in Name: # this is more convenient but no error
print("Sorry the letter can not be found")
else:
print(Name.replace(Letter,Repl))
+ 3
Correct the 3rd line.
Repl=input("Enter a replacement")
+ 2
Ohh eish
Don't know how I missed that
Thanks