Corrigés Bac Pratique Informatique
Section Math & Sciences & Technique
Mardi 24 mai 2022
Sujet1 ** Ondulant
from [Link] import loadUi
from [Link] import QApplication
def Ondulant(N):
ch=str(N)
i=0
x=True
l=len(ch)
while i<=l-3 and x:
if ch[i]!=ch[i+1] and ch[i]==ch[i+2]:
i=i+1
else:
x=False
return x
def Play():
Nch=[Link]()
if not [Link]():
[Link]("Veuillez introduire une valeur numérique ")
else:
N=int(Nch)
if N<100 :
[Link]("Veuillez introduire un nombre >=100")
else:
1
if Ondulant(N):
[Link](Nch+" est ondulant")
else:
[Link](Nch+" n'est pas ondulant")
app=QApplication([])
windows=loadUi("[Link]")
[Link]()
[Link](Play)
[Link]()
2
Sujet2 ** SuperPairPlus
from [Link] import loadUi
from [Link] import QApplication
def pariteChiffre(N):
x=True
while x and N!=0:
u=N%10
x=u%2==0
N=N//10
return x
def pariteDiviseur(N):
ok=True
i=2
while ok and i<=N:
if N%i==0:
ok=i%2==0
i=i+1
return ok
def SuperPairPlus(N):
return N%2==0 and pariteChiffre(N) and pariteDiviseur(N)
def Play():
Nch=[Link]()
if not [Link]():
[Link]("Veuillez introduire une valeur numérique ")
else:
N=int(Nch)
if N<=0 :
3
[Link]("Veuillez introduire un nombre >0")
else:
if SuperPairPlus(N):
[Link](Nch+" est SuperPairPlus")
else:
[Link](Nch+" n'est pas SuperPairPlus")
app=QApplication([])
windows=loadUi("[Link]")
[Link]()
[Link](Play)
[Link]()
4
Sujet3 ** SemiPremier
from [Link] import loadUi
from [Link] import QApplication
def premier(N):
i=2
while i<=N//2 and N%i!=0:
i=i+1
return i>N//2
def SemiPremier(N):
ok=False
if not premier(N):
i=2
while not ok and i<=N//2:
if premier(i):
j=N//i
if premier(j) and N%i==0:
ok=True
i=i+1
return ok
def Play():
Nch=[Link]()
if not [Link]():
[Link]("Veuillez introduire une valeur numérique ")
else:
N=int(Nch)
if N<=2 :
[Link]("Veuillez introduire un nombre >2")
else:
if SemiPremier(N):
5
[Link](Nch+" est Semi Premier")
else:
[Link](Nch+" n'est pas Semi Premier")
[Link](msg)
app=QApplication([])
windows=loadUi("[Link]")
[Link]()
[Link](Play)
[Link]()
6
Sujet4 ** Lisse
from [Link] import loadUi
from [Link] import QApplication
from math import *
def premier(N):
i=2
while i<=N//2 and N%i!=0:
i=i+1
return i>N//2
def Lisse(N):
ok=False
if premier(N):
pgd=N
else:
i=N//2
while i>=2 and not ok:
if premier(i) and N%i==0:
pgd=i
ok=True
i=i-1
return pgd
def Play():
Nch=[Link]()
if not [Link]():
[Link]("Veuillez introduire une valeur numérique ")
else:
N=int(Nch)
if N<=1 :
[Link]("Veuillez introduire un nombre > 1")
7
else:
if Lisse(N)<=sqrt(N):
[Link](Nch+" est un nombre Lisse")
else:
[Link](Nch+" n'est pas un nombre Lisse")
[Link](msg)
app=QApplication([])
windows=loadUi("[Link]")
[Link]()
[Link](Play)
[Link]()
8
Sujet5 ** HAbondant
# Solution : Affichage des nombres entre deux bornes
from [Link] import loadUi
from [Link] import QApplication
def SomDiv(N):
s=N
for i in range(1,N//2 +1):
if N%i==0:
s=s+i
return s
def HAbondant(N):
ok=True
i=N-1
S=SomDiv(N)
while i>=1 and ok:
if SomDiv(i) > S:
ok=False
else :
i=i-1
return ok
def Play():
Nch1=[Link]()
Nch2=[Link]()
if not [Link]() or [Link]()==False:
[Link]("Veuillez introduire une valeur numérique ")
else:
9
N1=int(Nch1)
N2=int(Nch2)
if N1<=1 or N2<=1:
[Link]("Veuillez introduire un nombre > 1 ")
else:
msg=''
for i in range(N1,N2+1):
if HAbondant(i):
msg=msg+str(i)+'|'
[Link](msg[:-1])
app=QApplication([])
windows=loadUi("[Link]")
[Link]()
[Link](Play)
[Link]()
10
''' Solution : Affichage sans bornes
from [Link] import loadUi
from [Link] import QApplication
def SomDiv(N):
s=N
for i in range(1,N//2 +1):
if N%i==0:
s=s+i
return s
def HAbondant(N):
ok=True
i=N-1
S=SomDiv(N)
while i>=1 and ok:
if SomDiv(i) > S:
ok=False
else :
i=i-1
return ok
def Play():
Nch=[Link]()
if not [Link]():
[Link]("Veuillez introduire une valeur numérique ")
else:
N=int(Nch)
if N<=1 :
[Link]("Veuillez introduire un nombre > 1")
11
else:
if HAbondant(N):
[Link](Nch+" est un nombre Hautement Abondant")
else:
[Link](Nch+" n'est pas un nombre Hautement
Abondant")
app=QApplication([])
windows=loadUi("[Link]")
[Link]()
[Link](Play)
[Link]()
'''
12