I’m trying to write a solution for UVa 860, but when I send it through vJudge it keeps saying “Runtime Error”.
from sys import stdin
import math
def main():
end_of_input = False
lambda_words = 0
dictionary = {}
text_entropy = 0
relative_entropy = 0
while not end_of_input:
line = stdin.readline().strip()
if line == "****END_OF_INPUT****":
end_of_input = True
else:
if line == "****END_OF_TEXT****":
print("%s %.1f %d" % (lambda_words, text_entropy, relative_entropy))
# print(lambda_words, round(text_entropy, 1), round(relative_entropy))
dictionary = {}
lambda_words = 0
text_entropy = 0
relative_entropy = 0
else:
line = line.replace(',', ' ')
line = line.replace('.', ' ')
line = line.replace(':', ' ')
line = line.replace(';', ' ')
line = line.replace('!', ' ')
line = line.replace('?', ' ')
line = line.replace('"', ' ')
line = line.replace('(', ' ')
line = line.replace(')', ' ')
line = line.lower()
words = line.split()
lambda_words += len(words)
for word in words:
if word in dictionary:
dictionary[word] += 1
else:
dictionary[word] = 1
text_entropy = 0
for word in dictionary:
text_entropy += dictionary[word]*(math.log10(lambda_words) - math.log10(dictionary[word]))
text_entropy = text_entropy / lambda_words
max_entropy = math.log10(lambda_words)
relative_entropy = (text_entropy / max_entropy) * 100
return 0
main()
I’ve tried almost everything, I’ve checked the different types of error in Python and nothing seems to help.
I’m needing a hand, hope you could help me! 🙂
New contributor
Joshua Mendez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.