「T」の文字を2つの異なる方法で削除する関数を作成するのに苦労しています。これparameter
はBoolean
、パラメータがのTrue
場合、ユーザー入力(以下の私のコードで記述されています)を出力し、ユーザーが「quit」と入力するまで、およびユーザーが「quit」と入力するまで、同じ入力を要求し続けます。次に、文字列内のすべての小文字の「t」を削除します。の場合、同じプロセスBoolean
がFalse
適用されますが、小文字の「t」を取り出す代わりに、大文字の「T」を取り出します。また、以下のコードで書いたのと同じタイプのフォーマットを維持したいと思います。ありがとうございます。ところで、私はpython2.4を使用しています。
def removeT(Boolea): userInput=str(input("Enter a word/sentence you want to process: ")) while userInput: string = (raw_input("Enter a word/sentence you want to process:")) if Boolea == False: userInput = userInput + string while "T" in userInput: index = userInput.find("T") userInput = userInput[:index] + userInput[index+1:] if string == "quit": keepAsking = False return userInput else: userInput = userInput + string while "t" in userInput: index = userInput.find("t") userInput = userInput[:index] + userInput[index+1:] while "T" in userInput: index = userInput.find("T") userInput = userInput[:index] + userInput[index+1:]