python compiler to c++ code example
Example 1: python to c++ transpiler
# Note: The last time I tested something was missing so I couldn't work
import pathlib
import transpyle
path = pathlib.Path('my_script.py')
code_reader = transpyle.CodeReader()
code = code_reader.read_file(path)
from_language = transpyle.Language.find('Python 3.6')
to_language = transpyle.Language.find('Fortran 95')
translator = transpyle.AutoTranslator(from_language, to_language)
fortran_code = translator.translate(code, path)
print(fortran_code)
Example 2: python compiler to c++
from random import*
def nim_aleatoire(n,max=4):
rep=input("_Voulez vous commencer ?")
if rep == "oui":
a=int(input("nb retire="))
b = randrange (1,max)
print("_python retire",b)
n = n - a
n= n - b
print("il reste",n)
else:
b = randrange (1,max)
print("_python retire",b)
n = n - b
print("il reste",n)
while n >= 1:
a=int(input("nb retire="))
b = randrange (1,max)
n1 = n - a
if n1 == 1:
b=1
n2= n1 - b
n=n2
print("_python retire",b)
print("il reste",n2)
if n1 == 1:
print("*vous avez gagne*")
if n2 == 1:
print("*vous avez perdu*")
if n1 == 0:
print("*vous avez perdu*")
def nim_gagnant(n,max=4):
if (n-1)%(max+1) == 0:
print("_Je vous laisse commencer")
while n >= 1:
a=int(input("nb retire="))
n1= n - a
b = (max+1) - (n - n1)
if n1 == 0:
b=0
print("_je retire",b)
n2= n1-b
print("il reste",n2)
n = n2
if n1 == 0:
print("Il ne reste plus d'allumettes")
print("*vous avez perdu*")
if (n-1)%(max+1) and n != 0:
print("_je commence")
while n >= 1:
if n%(max+1)==0:
b= max
print("_je retire",b)
print("il reste",n-b)
else:
b= n%(max+1) - 1
print("_je retire",b)
print("il reste",n-b)
a=int(input("nb retire="))
n1= n - a
n2= n1 - b
n=n2
print("Il ne reste plus d'allumettes")
print("*vous avez perdu*")