+ 4
How to make Python continue after if statement
I'm testing if "l" or "r" are in a message and replacing it. It stops after the if statement. If I input: "play pirate", it should return "pway piwate" but it only replaces the word "play". How do I do it for all words? https://code.sololearn.com/cqPGr7nvf9Ir/?ref=app
8 Respostas
+ 10
You can just replace the *elif* with an *if*.
Doing so will make the code to check both of the conditions instead of only one.
https://code.sololearn.com/cqXv04YyvTF1/?ref=app
+ 7
"". join["w" if c in["l", "r"] else c for c in list(message)]
https://code.sololearn.com/cP8mz8YnWilg/?ref=app
+ 7
A bit late with my post, but it shows a simplified version of the code.
There are 2 conditional statements to check if the desired characters are in the input string. You can just omit them. You can just call the 2 replace() functions. It will be faster and do the job.
def uWuFy(msg):
msg = msg.replace("l", "w")
msg = msg.replace("r", "w")
return msg
msg = input()
print(uWuFy(msg))
+ 5
i used a for loop to iterate the words, then used your conditionals to change the letters on each.
it may also have to do with the "elif" statement. Because you checked both words for the occurence of "l" first. each time, you check BOTH words, so that test always comes back true, meaning you will never reach the "elif" statement
https://code.sololearn.com/cTTvoW9PCLJo/?ref=app
+ 4
Lol Arsenic i just edited mine.. Im not trying to be a duck i swear.
+ 2
Steve Barongo Mong'are That was the cause of the issue before!
- 2
Use elif