I am creating a program that takes an input string from a user, then strips the punctuation from the string using the ord function. It should then calculate the position of each word (starting from 1) and disregard any repeated words. The compressed sentence, should be written to a text file as should the positions.
The problem with my code is that the input string is split into individual letters and the position count, counts individual letters. I am sure there is a simple fix but 84 versions later i have run out of ideas.
import string
sentence=input("Please enter a sentence: ")
sentence=sentence.upper()
sentencelist = open("sentence_List.txt","w")
sentencelist.write(str(sentence))
sentencelist.close()
words=list(str.split(sentence))
wordlist=len(words)
position=[]
text=()
uniquewords=[]
texts=""
nsentence=(sentence)
for c in list(sentence):
if not ord(c.lower()) in range(97,122):
nsentence=nsentence.replace(c, "")#Ascii a-z
print(nsentence)
nsentencelist=len(nsentence)
print(nsentencelist)
nsentencelist2 = open("nsentence_List.txt","w")
nsentencelist2.write(str(nsentence))
nsentencelist2.close()