when I run this, I get the following error: Does anybody know what might be causing this? The purpose of this program is to create an array, remove all punctuation from the array, and remove all lowercase characters from the array
File "words.py", line 37 else: ^ SyntaxError: invalid syntax
shell returned 1
import sys
from scanner import *
arr=[]
def main():
print("the name of the program is",sys.argv[0])
for i in range(1,len(sys.argv),1):
print(" argument",i,"is", sys.argv[i])
tokens = readTokens("text.txt")
cleanTokens = depunctuateTokens(arr)
words = decapitalizeTokens(result)
def readTokens(s):
s=Scanner("text.txt")
token=s.readtoken()
while (token != ""):
arr.append(token)
token=s.readtoken()
s.close()
return arr
def depunctuateTokens(arr):
result=[]
for i in range(0,len(arr),1):
string=arr[i]
cleaned=""
punctuation="""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
for i in range(0,len(string),1):
if string[i] not in punctuation:
cleaned += string[i]
result.append(cleaned)
print(result)
return result
def decapitalizeTokens(result):
if (ord(result) <= ord('Z')):
return chr(ord(result) + ord('a') - (ord('A'))
else:
return result
main()