In [1]:
#Écrire un algorithme qui affiche un damier de n * c cases, chaque case étant constituée de c*c caractères
n = int(input("n? "))
c = int(input("c? "))
i = n * c
while i > 0:
    i = i - 1
    ligne = ""
    j = n * c
    while j > 0:
        j = j - 1
        a = i // c
        b = j // c
        if (a + b) % 2 == 0:
            ligne = ligne + "."
        else:
            ligne = ligne + "#"
    print(ligne)


n? 6
c? 4
....####....####....####
....####....####....####
....####....####....####
....####....####....####
####....####....####....
####....####....####....
####....####....####....
####....####....####....
....####....####....####
....####....####....####
....####....####....####
....####....####....####
####....####....####....
####....####....####....
####....####....####....
####....####....####....
....####....####....####
....####....####....####
....####....####....####
....####....####....####
####....####....####....
####....####....####....
####....####....####....
####....####....####....

In [2]:
#Exercice de lecture d'algorithme. 
#Que fait l'algorithme suivant ? 

x = 11
n = 0
while n < 10:
    print(n, x)
    if x % 2 == 0:
        x = x // 2
    else:
        x = 3 * x + 1
    n = n + 1


0 11
1 34
2 17
3 52
4 26
5 13
6 40
7 20
8 10
9 5

In [3]:
#Exercice du mini-contrôle : horaires d'ouverture d'un magasin

jour = str("jour")
while (jour != "lundi" and jour != "mardi" and jour != "mercredi" and jour != "jeudi" and jour != "vendredi" and jour != "samedi" and jour != "dimanche" and jour != "Lundi" and jour != "Mardi" and jour != "Mercredi" and jour != "Jeudi" and jour != "Vendredi" and jour != "Samedi" and jour != "Dimanche") :
    jour = str(input("Entrez le jour souhaité : "))
    
    if (jour != "lundi" and jour != "mardi" and jour != "mercredi" and jour != "jeudi" and jour != "vendredi" and jour != "samedi" and jour != "dimanche" and jour != "Lundi" and jour != "Mardi" and jour != "Mercredi" and jour != "Jeudi" and jour != "Vendredi" and jour != "Samedi" and jour != "Dimanche") :
        print("Rentrez un jour valide")
        
temps = str("temps")
while (temps != "matin" and temps != "après-midi" and temps != "apres-midi" and temps != "après midi" and temps != "apres midi") :
    temps = str(input("Entrez le moment de la journée souhaité : "))
    
    if (temps != "matin" and temps != "après-midi" and temps != "apres-midi" and temps != "après midi" and temps != "apres midi") :
        print("Rentrez un moment de la journée valide")
        
def donnerHoraire(jour,temps) :
    #Entrées : Le jour
    #Sortie : /
    #Pré cond : Jour existant
    #Post cond : affiche les horaire pour le jour indiquer

    if (temps == "matin") :
        
        if (jour == "lundi") :
            print ("Ouvert de 10h à 12h")

        elif (jour == "mardi" or jour == "jeudi"or jour == "vendredi") :
            print("Ouvert de 8h à 12h")

        elif (jour == "samedi") :
            print("Ouvert de 9h à 11h")

        else :
            print("C'est fermé")
            
    else :

        if (jour == "lundi" or jour == "mercredi") :
            print("Overt de 14h à 16h")

        elif (jour == "mardi") :
            print("Ouvert de 14h à 17h")

        elif (jour == "jeudi") :
            print("Ouvert de 13h à 15h")

        else :
            print("C'est fermé")
            
        

donnerHoraire(jour,temps)


Entrez le jour souhaité : mardi
Entrez le moment de la journée souhaité : matin
Ouvert de 8h à 12h

In [5]:
# Correction de l'exercice de conversion d'une durée en Heures, minutes et secondes

def sed(sec):

    m = sec // 60
    s = sec % 60
    h = m // 60
    m = m % 60
    j = h //24
    h = h %24    
    
    return j, h, m, s
    
print("121s = 2mn01 =>", sed(121))
print("3661s = 1h1mn1seconde =>", sed(3661))
print("90061s = 1j1h1mn1sec", sed(90061))
print("120s = 2mn00 =>", sed(120))
print("3600s = 1h =>", sed(3600))


121s = 2mn01 => (0, 0, 2, 1)
3661s = 1h1mn1seconde => (0, 1, 1, 1)
90061s = 1j1h1mn1sec (1, 1, 1, 1)
120s = 2mn00 => (0, 0, 2, 0)
3600s = 1h => (0, 1, 0, 0)

In [9]:
# Somme des termes d'une suite arithmétique
def suiteArithmetique(raison, n):
    
    somme = 0 
    for k in range(0, n):
        somme = somme + raison * k 

    return somme

suiteArithmetique(4, 8)


Out[9]:
112

In [10]:
# Exercice : prédire les valeurs des variables qui seront affichées par le print : 
a = 19
b = 6
q = 0
r = a # r = 19
r = r - b # r = 13
q = q+1 # q = 1
r = r - b # r = 7
q = q + 1 # q = 2
r = r - b # r = 1
q = q + 1 # q = 3


print(a, b, q, r)


19 6 3 1

In [ ]:
def affichedamier(x,y,c,d):
	a=0
	for l in range(y):
		for m in range(y):
			for i in range(x):
				for j in range(2):
					for k in range(x):
						if a==0:
							if i%2==0 and j%2==0:
								print(c,end='')
							elif i%2==0 and j%2!=0:
								print(d,end='')
							else:
								print(" ",end='')
						else:
							if i%2!=0 and j%2!=0:
								print(c,end='')
							elif i%2!=0 and j%2==0:
								print(d,end='')
							else:
								print(" ",end='')
			print()
		if a==0:
			a=1
		else:
			a=0



print("Bienvenue dans le dessinateur à damier")
x=int(input("Choisissez un nombre de colonnes "))
y=int(input("Le nombre de lignes "))
c=input("Premier caractere")
d=input("Second caractere")
affichedamier(x,y,c,d)
a=input()


Bienvenue dans le dessinateur à damier
Choisissez un nombre de colonnes 4
Le nombre de lignes 2
Premier caracteree
Second caracterer
eeeerrrr        eeeerrrr        
eeeerrrr        eeeerrrr        
        rrrreeee        rrrreeee
        rrrreeee        rrrreeee

In [ ]: