Bonjour, pouvez vous m'aidez a traduire cet algorithme en python Définir mystere(x,y) Tant que x est non nul faire Si x est pair x ← x/2 y ← 2y Sinon x←x-1 z=z+
Informatique
volgar114
Question
Bonjour, pouvez vous m'aidez a traduire cet algorithme en python
Définir mystere(x,y)
Tant que x est non nul faire
Si x est pair
x ← x/2
y ← 2y
Sinon
x←x-1
z=z+y
Fin Si
Fin Tant que
Afficher z.
Définir mystere(x,y)
Tant que x est non nul faire
Si x est pair
x ← x/2
y ← 2y
Sinon
x←x-1
z=z+y
Fin Si
Fin Tant que
Afficher z.
1 Réponse
-
1. Réponse maximefluns
Explications:
Hey !
def mystère(x, y):
while x:
if x % 2 == 0:
x /= 2
y *= 2
else:
x -= 1
z += y
print(z)
Bonne soirée !