Correction Bac Pratique Scientifique 2024

Télécharger au format pdf ou txt
Télécharger au format pdf ou txt
Vous êtes sur la page 1sur 6

02/02/2024 23:48 bac 2024 8h.

py

1 #bac 2024 1er sujet


2 from numpy import *
3
4 def ceertab(ch):
5 global t
6 for i in range(len(ch)):
7 t[i]=int(ch[i])
8 def trie(t,n):
9
10 for i in range(0,len(ch)-1):
11 for j in range(i,len(ch)):
12 if(t[i]>t[j]):
13 tmp=t[i]
14 t[i]=t[j]
15 t[j]=tmp
16
17 def succ(t,n):
18 c=t[1]-t[0]
19 i=2
20 test=True
21 while((i<n) and (test==True)):
22 if(t[i]-t[i-1]!=c):
23 test=False
24 else:
25 i=i+1
26 return test
27
28 ch1=input("donner ch1:")
29 ch2=input("donner ch2:")
30 ch=ch1+ch2
31 print(" la chaine=",ch)
32 t=array([int]*(len(ch)))
33 ceertab(ch)
34 n=len(ch)
35 trie(t,n)
36 print(t)
37 b=succ(t,n)
38 if(b==True):
39 print("sucession parfaite")
40 else:
41 print("sucession non parfaite")
42

file:///C:/PySchool/3.10-32-bit/user_data/thonny/temp/thonny_vguloux4.html 1/1
02/02/2024 23:47 bac 2024 2ieme_sujet.py

1 #bac 2024 2ieme sujet


2 def rotation(ch):
3 res=""
4 for i in range(len(ch)):
5 res=res+chr(97+(ord(ch[i])-97 +13) % 26)
6 return res
7
8 def miroir(ch1):
9 lg=len(ch1)
10 ch2=""
11 for i in range(lg):
12 ch2=ch2+ch1[-1-i]
13 return ch2
14 def verifcar(ch):
15 test=True
16 i=0
17 while((i<len(ch))and(test==True)):
18 if("a"<=ch[i]<="z"):
19 i=i+1
20 else:
21 test=False
22 return test
23 def verif(ch):
24 lg=len(ch)
25 if((lg==0)or(lg>10)or (verifcar(ch)==False)):
26 return False
27 else:
28 return True
29 ch=input("donner une chaine:")
30 while not (verif(ch)):
31 ch=input("donner une chaine:")
32 chres=rotation(ch)
33 print("chaine apres rotation:",chres)
34 chmir=miroir(chres)
35 print("chaine miroir:",chmir)

file:///C:/PySchool/3.10-32-bit/user_data/thonny/temp/thonny_70axae_7.html 1/1
02/02/2024 23:47 bac 2024 3ieme sceance.py

1 def miroir(mot):
2 lm=len(mot)
3 chm=""
4 for i in range(lm):
5 chm=chm+mot[-1-i]
6 return chm
7
8 def verifcar(ch):
9 test=True
10 i=0
11 while((i<len(ch))and(test==True)):
12 if(("a"<=ch[i]<="z")or(ch[i]==" ")):
13 i=i+1
14 else:
15 test=False
16 return test
17
18 def verifesp(ch):
19 p_esp=ch.find(" ")
20 if( ch[p_esp+1]==" "):
21 print("entre 2 mots un seul espace est autorisé")
22 return False
23 else:
24 return True
25
26 def verif(ch):
27 lg=len(ch)
28 if((lg==0)or(lg>50)or (verifcar(ch)==False) or(verifesp(ch)==False)):
29 return False
30 else:
31 return True
32 valide=False
33 while(valide==False):
34 ch=input("saisir une chaine:")
35 valide=(verif(ch))
36 p=ch.find(" ")
37 chinv=""
38 while(p!=-1):
39 chr=ch[0:p]
40 chinv=chinv+" "+miroir(chr)
41 ch=ch[p+1:len(ch)]
42 p=ch.find(" ")
43 chr=ch
44 chinv=chinv+" "+miroir(chr)
45 print("la chaine inversée:",chinv)

file:///C:/PySchool/3.10-32-bit/user_data/thonny/temp/thonny_ts8lhmk6.html 1/1
02/02/2024 23:45 bac 2024 4ieme_sujet.py *

1 from numpy import *


2 #fonction qui permet de chercher le nombre des mots dans une phrase
3 def nb_mot(ch):
4 cp=0
5 p=ch.find(" ")
6 while(p!=-1):
7 cp=cp+1
8 ch=ch[p+1:len(ch)]
9 p=ch.find(" ")
10 return cp+1
11 #procedure qui permet de mettre chaque mot dans une case du tableau
12 def decoupe(ch):
13 global tch
14 p=ch.find(" ")
15 i=0
16 while(p!=-1):
17 tch[i]=ch[0:p]
18 i=i+1
19 ch=ch[p+1:len(ch)]
20 p=ch.find(" ")
21 tch[i]=ch[p+1:len(ch)-1]
22 #procedure au quel on mesure la longueur de chaque mot
23 def longt(tch,n):
24 global tlg
25 for i in range(n):
26 tlg[i]=len(tch[i])
27 #procedure qui permet de trie le tableau de longueur de chaine , ainsi que le tableau de chaine
28 def trie(tlg):
29 for i in range(n):
30 for j in range(n):
31 if(tlg[i]<tlg[j]):
32 tmp=tlg[i]
33 tmpch=tch[i]
34 tlg[i]=tlg[j]
35 tch[i]=tch[j]
36 tlg[j]=tmp
37 tch[j]=tmpch
38 #saisie d'une chaine
39 def verifesp(ch):
40
41 p_esp=ch.find(" ")
42
43 if( ch[p_esp+1]==" "):
44 print("entre 2 mots un seul espace est autorisé")
45 return False
46 else:
47 return True
48 def verifcar(ch):
49 test=True
50 i=0
51 while((i<len(ch))and(test==True)and(ch[i]!=".")):
52 if(("a"<=ch[i]<="z")or(ch[i]==" ")):
53 i=i+1
54
55 else:
56 test=False
57
58 return test
59 def verif(ch):
60 lg=len(ch)
61
62 if((lg==0)or(lg>50)or (ch[lg-1]!=".")or (verifcar(ch)==False)or (verifesp(ch)==False)):
63 return False
64 else:
65 return True
66 def saisie():
67 global ch
68 ch=input("donner une chaine:")
69 while not (verif(ch)):
file:///C:/PySchool/3.10-32-bit/user_data/thonny/temp/thonny_17nhl1xg.html 1/2
02/02/2024 23:45 bac 2024 4ieme_sujet.py *
70 ch=input("donner une chaine:")
71
72
73 #programme principale
74 saisie()
75 n=nb_mot(ch)
76 print("le nombre de mots:",n)
77 tch=array([str]*n)
78 decoupe(ch)
79 for i in range(n):
80 print(tch[i],end="|")
81 print("\n")
82 tlg=array([int]*n)
83 longt(tch,n)
84 for i in range(n):
85 print(tlg[i],end="|")
86 trie(tlg)
87 print("\n le tableau de longueur trie:")
88 for i in range(n):
89 print(tlg[i],end="|")
90 print("\n le tableau de chaine trie:")
91 for i in range(n):
92 print(tch[i],end="|")
93

file:///C:/PySchool/3.10-32-bit/user_data/thonny/temp/thonny_17nhl1xg.html 2/2
02/02/2024 23:46 bac 2024 5ieme_sujet.py *

1 def verifcar(ch):
2 test=True
3 i=0
4 while((i<len(ch))and(test==True)):
5 if("a"<=ch[i]<="z"):
6 i=i+1
7 else:
8 test=False
9 return test
10 def verif(ch):
11 lg=len(ch)
12 if((lg==0)or(lg>30)or (verifcar(ch)==False)):
13 return False
14 else:
15 return True
16 def saisie():
17 ch=input("donner une chaine:")
18 while not (verif(ch)):
19 ch=input("donner une chaine:")
20 return ch
21 def chercher(x,y):
22 ch=""
23 for i in range(len(x)):
24 for j in range(len(y)):
25 if(x[i]==y[j]):
26 p=ch.find(x[i])
27 if(p==-1):
28 ch=ch+x[i]
29 print(ch)
30 #programme principale
31 ch1=saisie()
32 ch2=saisie()
33 chercher(ch1,ch2)
34

file:///C:/PySchool/3.10-32-bit/user_data/thonny/temp/thonny_apo7aueo.html 1/1

Vous aimerez peut-être aussi