{"id":14350,"date":"2021-10-01T10:30:03","date_gmt":"2021-10-01T05:00:03","guid":{"rendered":"https:\/\/python-programs.com\/?p=14350"},"modified":"2021-11-22T18:33:29","modified_gmt":"2021-11-22T13:03:29","slug":"python-program-to-print-all-co-binary-palindromic-numbers-in-a-range","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-all-co-binary-palindromic-numbers-in-a-range\/","title":{"rendered":"Python Program to Print All Co-binary Palindromic Numbers in a Range"},"content":{"rendered":"
Given the lower limit range and upper limit range, the task is to print all Co-binary Palindromic Numbers in the given range in Python.<\/p>\n
Co-binary Palindromic Numbers:<\/strong><\/p>\n A co-binary palindrome is a number that is a palindrome both as a decimal number and after being binary transformed.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print all Co-binary Palindromic Numbers in the given range in Python.<\/p>\n Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners<\/a> tutorial.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Given the lower limit range and upper limit range, the task is to print all Co-binary Palindromic Numbers in the given range in Python. Co-binary Palindromic Numbers: A co-binary palindrome is a number that is a palindrome both as a decimal number and after being binary transformed. Examples: Example1: Input: Given upper limit range =11 …<\/p>\nGiven upper limit range =11\r\nGiven lower limit range =2426<\/pre>\n
The Co-binary palindrome numbers in the given range 11 and 2426 are:\r\n33 99 313 585 717<\/pre>\n
Given upper limit range =5\r\nGiven lower limit range =12564<\/pre>\n
The Co-binary palindrome numbers in the given range 5 and 12564 are:\r\n5 7 9 33 99 313 585 717 7447 9009<\/pre>\n
Program to Print All Co-binary Palindromic Numbers in a Range in<\/h2>\n
Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Create a function checkpalindromicNumb() which accepts the string as an argument and\r\n# returns true if the string is palindrome else it returns False.\r\ndef checkpalindromicNumb(val):\r\n return val == val[::-1]\r\n# Create a function convertBinar() which converts the given number to binary and returns it.\r\ndef convertBinar(orinumb):\r\n return bin(orinumb)[2:]\r\n# Give the lower limit range as static input and store it in a variable.\r\nlowlimrange = 11\r\n# Give the upper limit range as static input and store it in another variable.\r\nupplimrange = 2426\r\nprint('The Co-binary palindrome numbers in the given range',\r\n lowlimrange, 'and', upplimrange, 'are:')\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor itervalu in range(lowlimrange, upplimrange+1):\r\n # Convert this iterator value to binary by passing it as an argument\r\n # to convertBinar() function and store it in a variable say binarystrng.\r\n binarystrng = convertBinar(itervalu)\r\n # Convert this iterator value to a string\r\n # using the str() function say strngnumb.\r\n strngnumb = str(itervalu)\r\n # Check if the strngnumb is palindrome or not by giving the given strngnumb\r\n # as an argument to checkpalindromicNumb().\r\n # Check if the binarystrng is palindrome or not by giving the given\u00a0binarystrng\r\n # as an argument to checkpalindromicNumb().\r\n # Check if both statements are true using the and operator and If conditional Statement.\r\n if(checkpalindromicNumb(binarystrng) and checkpalindromicNumb(strngnumb)):\r\n # If it is true then print it.\r\n print(strngnumb, end=' ')\r\n<\/pre>\n
The Co-binary palindrome numbers in the given range 11 and 2426 are:\r\n33 99 313 585 717<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Create a function checkpalindromicNumb() which accepts the string as an argument and\r\n# returns true if the string is palindrome else it returns False.\r\ndef checkpalindromicNumb(val):\r\n return val == val[::-1]\r\n# Create a function convertBinar() which converts the given number to binary and returns it.\r\ndef convertBinar(orinumb):\r\n return bin(orinumb)[2:]\r\n\r\n# Give the lower limit range and upper limit range as\r\n# user input using map(),int(),split() functions.\r\n# Store them in two separate variables.\r\nlowlimrange, upplimrange = map(int, input(\r\n 'Enter lower limit range and upper limit range separate bt spaces = ').split())\r\nprint('The Co-binary palindrome numbers in the given range',\r\n lowlimrange, 'and', upplimrange, 'are:')\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor itervalu in range(lowlimrange, upplimrange+1):\r\n # Convert this iterator value to binary by passing it as an argument\r\n # to convertBinar() function and store it in a variable say binarystrng.\r\n binarystrng = convertBinar(itervalu)\r\n # Convert this iterator value to a string\r\n # using the str() function say strngnumb.\r\n strngnumb = str(itervalu)\r\n # Check if the strngnumb is palindrome or not by giving the given strngnumb\r\n # as an argument to checkpalindromicNumb().\r\n # Check if the binarystrng is palindrome or not by giving the given\u00a0binarystrng\r\n # as an argument to checkpalindromicNumb().\r\n # Check if both statements are true using the and operator and If conditional Statement.\r\n if(checkpalindromicNumb(binarystrng) and checkpalindromicNumb(strngnumb)):\r\n # If it is true then print it.\r\n print(strngnumb, end=' ')\r\n<\/pre>\n
Enter lower limit range and upper limit range separate bt spaces = 5 12564\r\nThe Co-binary palindrome numbers in the given range 5 and 12564 are:\r\n5 7 9 33 99 313 585 717 7447 9009<\/pre>\n
\n