-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzad.py
72 lines (63 loc) · 1.85 KB
/
zad.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from collections import Counter
import requests
def menu():
print("1. Pobierz plik z internetu ")
print("2. Zlicz liczbę liter w pobranym pliku ")
print("3. Zlicz liczbę wyrazów w pliku ")
print("4. Zlicz liczbę znaków interpunkcyjnych w pliku ")
print("5. Zlicz liczbę zdań w pliku")
print("6. Wygeneruj raport o użyciu liter (A-Z) ")
print("7. Zapisz statystyki z punktów 2-5 do pliku statystyki.txt ")
print("8. Wyjście z programu ")
choice= int(input("Enter choice: "))
if choice==1:
url = "http://s3.zylowski.net/public/input/5.txt"
r = requests.get(url)
with open('file.txt', 'w') as file:
file.write(r.text)
elif choice==2:
plik = open('file.txt')
try:
tekst = plik.read()
finally:
plik.close()
num_of_char = len(tekst)
print('Count in text file :', num_of_char)
elif choice==3:
plik = open('file.txt')
try:
tekst = plik.read()
finally:
plik.close()
data = tekst.split(" ")
num_of_char = len(data)
print('Count in text file :', num_of_char)
elif choice==4:
try:
#inst
except FileNotFoundError:
print("Something goes wrong, download file again")
elif choice==5:
plik = open('file.txt')
try:
tekst = plik.read()
finally:
plik.close()
data = tekst.split(".")
num_of_char = len(data)
print('Count in text file :', num_of_char)
elif choice==6:
plik = open('file.txt')
freq = {}
for c in plik:
freq[c] = plik.count(c)
return freq
elif choice==7:
print("7")
elif choice==8:
print("8")
exit()
else:
print("Invalid choice")
menu()
menu()