## Exercice 1

# montxt=open('Test.txt')
# k=0
# for L in montxt:
#     k=k+1
#     print("Ligne",k,": ",L)
# montxt.close()
#
# Texte=montxt.read()
# montxt.close()
#
# print(Texte.upper())
# "super" in Texte

def Occurrences(a,S):
    k=0
    for s in S:
        if s==a:
            k=k+1
    return k

montxt=open('LaFontaine.txt')
Texte=montxt.read()
Texte=Texte.lower()
montxt.close()
print(Occurrences('e',Texte))
Alphabet='abcdefghijklmnopqrstuvwxyz'
# for a in Alphabet:
#     print(a,"apparaît",Occurrences(a,Texte),"fois")

montxt=open('Compte.csv','w')
for a in Alphabet:
    montxt.write(a+","+str(Occurrences(a,Texte))+"\n")
montxt.close()

## Exercice 2


import os
os.chdir("C:\\Users\\SONYPRO\\Desktop\\docs\\Info\\TP5_test\\Coordonnées_France")
from matplotlib.pyplot import *

# for n in range(1,29):
#     montxt=open('Coordonnees_France_'+str(n)+'.txt')
#     Texte=montxt.read()
#     montxt.close()
#     TS = Texte.split()
#     j=0
#     X=[]
#     Y=[]
#     for k in range(len(TS)):
#         if j==0:
#             X.append(float(TS[k]))
#             j=1
#         else:
#             Y.append(float(TS[k]))
#             j=0
#     plot(X,Y)
# axis("equal")
# show()


montxt=open('Coordonnees_France_Dept.txt')
Texte=montxt.read()
montxt.close()
TS = Texte.split()
j=0
X=[]
Y=[]
L=[]
p=0
for k in range(len(TS)-96):
    if TS[k]=="Département":
        L.append(TS[k+1])
        TS.remove(TS[k+1])
for k in range(len(TS)):
    if TS[k]=="Département":
        plot(X,Y,label=str(L[p]))
        p=p+1
        X=[]
        Y=[]
    elif TS[k]=="Cut":
        plot(X,Y)
        X=[]
        Y=[]
    elif j==0:
        X.append(float(TS[k]))
        j=1
    else:
        Y.append(float(TS[k]))
        j=0
plot(X,Y)
axis("equal")
legend()
show()