# ex09000_boucle_for.py
# La boucle for

from math import *

print("----- Exercice 9.0a -----")
machaine = "Ceci est un petit texte"
for cc in machaine:
    print(cc)

print("----- Exercice 9.0b -----")
strS = ""
for cc in machaine:
    strS = strS + cc + "; "
print(strS)

print("----- Exercice 9.1 chaine à l'envers-----")
strS = ""
for cc in machaine:
    strS = cc + strS
print(strS)


print("----- Exercice 9.2a -----")
# Affiche les nombres entiers de 0 à 11-1 sur une ligne,
# chaque nombre étant suivit d'un "; "
for nn in range(11):
    print(nn, end="; ")
print() # Sert à revenir à la ligne

# Affiche les nombres entiers de 4 à 10-1 sur une ligne,
# chaque nombre étant suivit d'un "; "
for nn in range(4, 10):
    print(nn, end="; ")
print() # Sert à revenir à la ligne

# Affiche les nombres entiers de 10 à 4+1, décroissants, sur une ligne,
# chaque nombre étant suivit d'un "; "
for nn in range(10, 4, -1):
    print(nn, end="; ")
print() # Sert à revenir à la ligne
print("Terminé")

print("----- Exercice 9.2b -----")
somme = 0
for nn in range(5):
    somme += nn
print("0 + 1 + 2 + 3 + 4 =", somme)

somme = 0
for nn in range(101):
    somme += nn
print("0 + 1 + 2 + 3 + ... + 100 =", somme)

somme = 0
for nn in range(1, 100001):
    somme += 1/nn**2
print("Somme des inverses des carrés =", somme)