{"id":18574,"date":"2021-08-26T10:38:26","date_gmt":"2021-08-26T05:08:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=18574"},"modified":"2021-11-22T18:37:18","modified_gmt":"2021-11-22T13:07:18","slug":"python-program-to-check-whether-product-of-digits-at-even-places-of-a-number-is-divisible-by-k","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-whether-product-of-digits-at-even-places-of-a-number-is-divisible-by-k\/","title":{"rendered":"Python Program to Check Whether Product of Digits at Even places of a Number is Divisible by K"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check Whether Sum of digits at Odd places of a Number is Divisible by K<\/a> 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 check if the product of digits at even places of a given number is divisible by the another given input number say K:<\/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 Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Check Whether Sum of digits at Odd places of a Number is Divisible by K The task is to check if the product of digits at even places of a given number is divisible by the another given input number say K. Examples: Example1: Input: …<\/p>\n
\nThe task is to check if the product of digits at even places of a given number is divisible by the another given input number say K.<\/p>\nGiven Number = 693214\r\nGiven another Number (k) = 2<\/pre>\n
The Product of digits at even places of the given number{ 693214 } is divisible by the another given number k{ 2 }<\/pre>\n
Given Number = 2578\r\nGiven another Number (k) = 4<\/pre>\n
The Product of digits at even places of the given number{ 2578 } is not divisible by the another given number k{ 4 }<\/pre>\n
Program to Check Whether Product of Digits at Even places of a Number is Divisible by K in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\ngvn_numb = 123456\r\n# Give the other number k as static input and store it in another variable.\r\ngvn_k = 5\r\n# Convert the given number to a string using the str() function and store it in\r\n# another variable.\r\nstringnum = str(gvn_numb)\r\n# Create a list of digits say \"digtslst\" using map(),list(),int functions.\r\ndigtslst = list(map(int, stringnum))\r\n# Take another variable say \"evn_prodt\" and initialize it with 1.\r\nevn_prodt = 1\r\n# Loop in the above list of digits until the length of the \"digtslst\" using the for loop.\r\nfor itr in range(len(digtslst)):\r\n # Check if the iterator value is even or not using\r\n # the if conditional statement.\r\n if(itr % 2 == 0):\r\n # If the statement is true, then multiply the element of digits list at iterator value to\r\n # the \"evn_prodt\" and store it in the same variable evn_prodt.\r\n evn_prodt *= digtslst[itr]\r\n# Check if the evn_prodt modulus given number k is equal to 0 or not using the if conditional\r\n# statement.\r\nif(evn_prodt % gvn_k == 0):\r\n # If the statement is true, then print \"The product of digits at even places of the given\r\n # number is divisible by the another given number k.\r\n print(\"The Product of digits at even places of the given number{\", gvn_numb,\r\n \"} is divisible by the another given number k{\", gvn_k, \"}\")\r\nelse:\r\n # If the statement is false, then print \"The product of digits at even places of the given\r\n # number is Not divisible by the another given number k.\r\n print(\"The Product of digits at even places of the given number{\", gvn_numb,\r\n \"} is not divisible by the another given number k{\", gvn_k, \"}\")\r\n<\/pre>\n
The Product of digits at even places of the given number{ 123456 } is divisible by the another given number k{ 5 }<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
#Give the number as user input using the int(input()) function and store it in a variable.\r\ngvn_numb = int(input(\"Enter some random number = \"))\r\n#Give the other number k as user input using the int(input()) function and store it in another variable.\r\ngvn_k = int(input(\"Enter some random number = \")) \r\n# Convert the given number to a string using the str() function and store it in\r\n# another variable.\r\nstringnum = str(gvn_numb)\r\n# Create a list of digits say \"digtslst\" using map(),list(),int functions.\r\ndigtslst = list(map(int, stringnum))\r\n# Take another variable say \"evn_prodt\" and initialize it with 1.\r\nevn_prodt = 1\r\n# Loop in the above list of digits until the length of the \"digtslst\" using the for loop.\r\nfor itr in range(len(digtslst)):\r\n # Check if the iterator value is even or not using\r\n # the if conditional statement.\r\n if(itr % 2 == 0):\r\n # If the statement is true, then multiply the element of digits list at iterator value to\r\n # the \"evn_prodt\" and store it in the same variable evn_prodt.\r\n evn_prodt *= digtslst[itr]\r\n# Check if the evn_prodt modulus given number k is equal to 0 or not using the if conditional\r\n# statement.\r\nif(evn_prodt % gvn_k == 0):\r\n # If the statement is true, then print \"The product of digits at even places of the given\r\n # number is divisible by the another given number k.\r\n print(\"The Product of digits at even places of the given number{\", gvn_numb,\r\n \"} is divisible by the another given number k{\", gvn_k, \"}\")\r\nelse:\r\n # If the statement is false, then print \"The product of digits at even places of the given\r\n # number is Not divisible by the another given number k.\r\n print(\"The Product of digits at even places of the given number{\", gvn_numb,\r\n \"} is not divisible by the another given number k{\", gvn_k, \"}\")\r\n<\/pre>\n
Enter some random number = 693214\r\nEnter some random number = 2\r\nThe Product of digits at even places of the given number{ 693214 } is divisible by the another given number k{ 2 }<\/pre>\n
\n