I have possible strings, where I would like to have a way to prevent unnecessary question marks and add if it is missing. However, this function applies only at the end of the string. Here is 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 value
- Can not I do this? Why ????
Expected / correct result:
- How do you go to the bathroom?
- Can I invest today? How much is the minimum value?
- Can not I do this? Why?
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 does not exist. In case I check the last 3 characters to prevent cases like: Am I alive?!
if "?" not in title[-3:]:
title += "?"