1
我是新來的python,我不知道如何讓這個程序忽略標點符號;我知道這真的是效率低下,但我現在還沒有爲此感到困擾。我怎樣才能讓這個程序忽略標點符號
while True:
y="y"
n="n"
Sentence=input("Please enter your sentence: ").upper()
print("Your sentence is:",Sentence)
Correct=input("Is your sentence correct? y/n ")
if Correct==n:
break
elif Correct==y:
Location=0
SplitSentence = Sentence.split(" ")
for word in SplitSentence:
locals()[word] = Location
Location+=1
print("")
FindWord=input("What word would you like to search? ").upper()
if FindWord not in SplitSentence:
print("Your chosen word is not in your sentence")
else:
iterate=0
WordBank=[]
for word in SplitSentence:
iterate=iterate+1
if word == FindWord:
WordBank.append(iterate)
print(FindWord, WordBank)
break
我感謝所有幫助您可以給我
你只是想剝離一切不是:a-zA-Z0-9還是你有一個標點符號來測試? – Fallenreaper