-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenzech.py
More file actions
28 lines (21 loc) · 1.15 KB
/
enzech.py
File metadata and controls
28 lines (21 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
# divided them by 100 and rounded in another program and then took the result here
en_freq = [0.08167, 0.01492, 0.02782, 0.04253, 0.12702, 0.02228, 0.02015, 0.06094, 0.06966, 0.00153, 0.00772, 0.04025, 0.02406, 0.06749, 0.07507, 0.01929, 0.00095, 0.05987, 0.06327, 0.09056, 0.02758, 0.00978, 0.0236, 0.0015, 0.01974, 0.00074]
cz_freq = [0.08421, 0.00822, 0.0074, 0.03475, 0.07562, 0.00084, 0.00092, 0.01356, 0.06073, 0.01433, 0.02894, 0.03802, 0.02446, 0.06468, 0.06695, 0.01906, 1e-05, 0.04799, 0.05212, 0.05727, 0.0216, 0.05344, 0.00016, 0.00027, 0.01043, 0.01503]
letters = [0]*26
english = 0
czech = 0
text = ""
for line in sys.stdin:
text = text + line.strip() + " "
for i in text:
if 123 > ord(i.lower()) > 96:
letters[ord(i.lower()) - ord('a')] += 1
letters_sum = sum(letters)
for i in range(26):
letter_freq = letters[i] / letters_sum
english = english + (letter_freq - en_freq[i]) ** 2 / en_freq[i]
czech = czech + (letter_freq - cz_freq[i]) ** 2 / cz_freq[i]
print(f"Match with English: {english:0.2f}")
print(f"Match with Czech: {czech:0.2f}")
print("Text is in English") if english < czech else print("Text is in Czech")