Vous êtes sur la page 1sur 12

Correction proposée par

Mme FATMA Knani


Corrigés Bac Pratique Informatique
Section Math & Sciences & Technique
Mardi 24 mai 2022

Sujet1 ** Ondulant
# ---- Correction proposée par Mme FATMA Knani ----
from PyQt5.uic import loadUi
from PyQt5.QtWidgets 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=windows.n.text()
if not Nch.isdigit():
msg="Veuillez introduire une valeur numérique "
else:
N=int(Nch)
if N<100 :
msg="Veuillez introduire un nombre >=100"

1
else:
if Ondulant(N):
msg=Nch+" est ondulant"
else:
msg=Nch+" n'est pas ondulant"
windows.res.setText(msg)

app=QApplication([])
windows=loadUi("InterfaceOndulant.ui")
windows.show()
windows.verif.clicked.connect(Play)
app.exec()

2
Sujet2 ** SuperPairPlus
# ---- Correction proposée par Mme FATMA Knani ----
from PyQt5.uic import loadUi
from PyQt5.QtWidgets 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=windows.n.text()
if not Nch.isdigit():
msg="Veuillez introduire une valeur numérique "
else:
N=int(Nch)
if N<=0 :

3
msg="Veuillez introduire un nombre >0"
else:
if SuperPairPlus(N):
msg=Nch+" est SuperPairPlus"
else:
msg=Nch+" n'est pas SuperPairPlus"
windows.res.setText(msg)

app=QApplication([])
windows=loadUi("InterfaceSuperPairPlus.ui")
windows.show()
windows.verif.clicked.connect(Play)
app.exec()

4
Sujet3 ** SemiPremier
# ---- Correction proposée par Mme FATMA Knani ----
from PyQt5.uic import loadUi
from PyQt5.QtWidgets 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=windows.n.text()
if not Nch.isdigit():
msg="Veuillez introduire une valeur numérique "
else:
N=int(Nch)
if N<=2 :
msg="Veuillez introduire un nombre >2"
else:

5
if SemiPremier(N):
msg=Nch+" est Semi Premier"
else:
msg=Nch+" n'est pas Semi Premier"
windows.res.setText(msg)

app=QApplication([])
windows=loadUi("InterfaceSemipremier.ui")
windows.show()
windows.verif.clicked.connect(Play)
app.exec()

6
Sujet4 ** Lisse
# ---- Correction proposée par Mme FATMA Knani ----
from PyQt5.uic import loadUi
from PyQt5.QtWidgets 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=windows.n.text()
if not Nch.isdigit():
msg="Veuillez introduire une valeur numérique "
else:
N=int(Nch)
if N<=1 :

7
msg="Veuillez introduire un nombre > 1"
else:
if Lisse(N)<=sqrt(N):
msg=Nch+" est un nombre Lisse"
else:
msg=Nch+" n'est pas un nombre Lisse"
windows.res.setText(msg)

app=QApplication([])
windows=loadUi("InterfaceLisse.ui")
windows.show()
windows.verif.clicked.connect(Play)
app.exec()

8
Sujet5 ** HAbondant
# ---- Correction proposée par Mme FATMA Knani ----
# Solution : Affichage des nombres entre deux bornes
from PyQt5.uic import loadUi
from PyQt5.QtWidgets 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=windows.n1.text()
Nch2=windows.n2.text()
if not Nch1.isdigit() or Nch2.isdigit()==False:
msg="Veuillez introduire une valeur numérique "

else:

9
N1=int(Nch1)
N2=int(Nch2)
if N1<=1 or N2<=1:
msg="Veuillez introduire un nombre > 1 "
else:
msg=''
for i in range(N1,N2+1):
if HAbondant(i):
msg=msg+str(i)+'|'
windows.res.setText(msg[:-1])

app=QApplication([])
windows=loadUi("InterfaceListHAbondant.ui")
windows.show()
windows.verif.clicked.connect(Play)
app.exec()

10
''' Solution : Affichage sans bornes
from PyQt5.uic import loadUi
from PyQt5.QtWidgets 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=windows.n.text()
if not Nch.isdigit():
msg="Veuillez introduire une valeur numérique "
else:
N=int(Nch)
if N<=1 :
msg="Veuillez introduire un nombre > 1"

11
else:
if HAbondant(N):
msg=Nch+" est un nombre Hautement Abondant"
else:
msg=Nch+" n'est pas un nombre Hautement Abondant"
windows.res.setText(msg)

app=QApplication([])
windows=loadUi("InterfaceHAbondant.ui")
windows.show()
windows.verif.clicked.connect(Play)
app.exec()
'''

12

Vous aimerez peut-être aussi