# C++ to Python code converter
def cplusplus_to_python(cplusplus_code):
# Step 1: Replace 'std::' with 'namespace::' for standard library elements
python_code = cplusplus_code.replace('std::', 'namespace::')
# Step 2: Replace 'cout' with 'print'
python_code = python_code.replace('cout', 'print')
# Step 3: Replace 'cin' with 'input'
python_code = python_code.replace('cin', 'input')
# Step 4: Replace 'endl' with ''
python_code = python_code.replace('endl', '')
# Step 5: Replace '<<' with '+'
python_code = python_code.replace('<<', '+')
# Step 6: Replace 'int main()' with 'if __name__ == "__main__":'
python_code = python_code.replace('int main()', 'if __name__ == "__main__":')
# Step 7: Replace 'return 0' with 'pass'
python_code = python_code.replace('return 0', 'pass')
return python_code
# Example usage:
cplusplus_code = """
#include <iostream>
using namespace std;
int main() {
int x, y;
cout << "Enter two numbers: ";
cin >> x >> y;
cout << "Sum: " << x + y << endl;
return 0;
}
"""
python_code = cplusplus_to_python(cplusplus_code)
print(python_code)