1

「T」の文字を2つの異なる方法で削除する関数を作成するのに苦労しています。これparameterBoolean、パラメータがのTrue場合、ユーザー入力(以下の私のコードで記述されています)を出力し、ユーザーが「quit」と入力するまで、およびユーザーが「quit」と入力するまで、同じ入力を要求し続けます。次に、文字列内のすべての小文字の「t」を削除します。の場合、同じプロセスBooleanFalse適用されますが、小文字の「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:]
4

1 に答える 1

0
def removeT(b):
    s1 = ""
    while True:
        s2 = raw_input("Enter a word/sentence you want to process: ")
        if s2 == "quit": return s1
        s2 = s2.replace("T", "")
        if b:
            s2 = s2.replace("t", "")
        s1 += s2
于 2012-09-27T02:54:03.707 に答える