-3
I have possible strings, where I would like to have a way to prevent unnecessary question marks and add if missing. However this function applies only at the end of the string. Follow the list below and the expected result:
Possible wrong strings:
- How do you go to the bathroom????
- Can I invest today? How much is the minimum amount
- Can’t I do that? 'Cause????
Expected/correct result:
- How do you go to the bathroom?
- Can I invest today? How much is the minimum amount?
- Can’t I do that? 'Cause?
I started the code and I already check if there is a question mark at the end of the string and add it if it doesn’t exist. In this case I check the last 3 characters to prevent cases like: I am alive?!
if "?" not in title[-3:]:
title += "?"
I already check if the last 3 characters have any question mark, if not I add at the end of the string. Now, the rest is not yet.
– Guilherme IA
By the way, will they always be questions? For example: "Can’t I do it today??? Okay." is not a valid entry in this case?
– Woss
Will always be questions.
– Guilherme IA