For example consider the following if == ' ': main (sys.argv[ :]) If the command line Python program itself is going to execute first, then contains the string " ". The condition if " "==" ": is true then the main function is called. sys.argv[ :] - get everything after the script name(file name). sys.argv[ ] is the script name (python program) Remember “string slicing” you have studied in chapter .
Note Python program Executing C++ Program using control statement . Now let us write a Python program to read a C++ coding and execute its result. The steps for executing the C++ program to check a given number is palindrome or not is given below 12th Computer Chapter - - Importing C++ Programs in Python Type the C++ program to check whether the input number is palindrome or not in notepad and save it as “ .cpp”. Click the Run Terminal and open the command window Type the command Python pali.py -i Type the Python program and save it as pali.py Step Step Step Step Example:- .
. - Write a C++ program to enter any number and check whether the number is palindrome or not using while loop. /*. To check whether the number is palindrome or not using while loop.*/ //Now select File->New in Notepad and type the C++ program #include <iostream> using namespace std; int main() { int n, num, digit, rev = ; cout<< "Enter a positive number: "; cin>>num; n = num; while(num) { digit = num % ; rev = (rev * ) + digit; num = num / ; } cout<< " The reverse of the number is: " << rev <<endl; if (n == rev) cout<< " The number is a palindrome"; else cout<< " The number is not a palindrome"; return ; } // Save this file as .cpp 12th Computer Chapter - - #Now select File→New in Notepad and type the Python program # Save the File as pali.py .
Program that compiles and executes a .cpp file # Python