{"id":18538,"date":"2021-08-26T10:38:41","date_gmt":"2021-08-26T05:08:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=18538"},"modified":"2021-11-22T18:37:17","modified_gmt":"2021-11-22T13:07:17","slug":"python-program-to-calculate-the-product-of-digits-of-a-number-at-even-and-odd-places","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-product-of-digits-of-a-number-at-even-and-odd-places\/","title":{"rendered":"Python Program to Calculate the Product of Digits of a Number at Even and Odd places"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check Whether Product of Digits at Even 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 determine whether or not the product of its digits at even and odd places is equal.<\/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 Product of Digits at Even places of a Number is Divisible by K Given a number, the task is to calculate whether or not the product of its digits at even and odd places. Examples: Example1: Input: Given Number = 432172 Output: The …<\/p>\n
\nGiven a number, the task is to calculate whether or not the product of its digits at even and odd places.<\/p>\nGiven Number = 432172<\/pre>\n
The product of all digits at even places in a given number{ 432172 } = 56\r\nThe product of all digits at odd places in a given number { 432172 } = 6<\/pre>\n
Given Number = 2134315<\/pre>\n
The product of all digits at even places in a given number{ 2134315 } = 90\r\nThe product of all digits at odd places in a given number { 2134315 } = 4<\/pre>\n
Program to Check if Product of Digits of a Number at Even and Odd places is Equal 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\nnumb = 432172\r\n# Convert the given number to string using the str() function.\r\nstringnum = str(numb)\r\n# Create a list of digits say \"digtslst\" using map(),list(),int functions.\r\ndigtslst = list(map(int, stringnum))\r\n# Take a variable say \"evn_sum\" and initialize it with 1.\r\nevn_prodt = 1\r\n# Take another variable say \"od_sum\" and initialize it with 1.\r\nod_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 iterator value of \"digtslst\" to the \"evn_prodt\"\r\n # and store it in the same variable evn_prodt.\r\n evn_prodt *= digtslst[itr]\r\n else:\r\n # If the statement is false, then add the iterator value of \"digtslst\" to the \"od_prodt\"\r\n # and store it in the same variable od_sum.\r\n od_prodt *= digtslst[itr]\r\n# Print \"evn_prodt\" to get the product of all digits at even places in a given number.\r\nprint(\r\n \"The product of all digits at even places in a given number{\", numb, \"} =\", evn_prodt)\r\n# Print \"od_prodt\" to get the product of all digits at odd places in a given number.\r\nprint(\r\n \"The product of all digits at odd places in a given number {\", numb, \"} =\", od_prodt)\r\n<\/pre>\n
The product of all digits at even places in a given number{ 432172 } = 56\r\nThe product of all digits at odd places in a given number { 432172 } = 6<\/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\nnumb = int(input(\"Enter some random number = \"))\r\n# Convert the given number to string using the str() function.\r\nstringnum = str(numb)\r\n# Create a list of digits say \"digtslst\" using map(),list(),int functions.\r\ndigtslst = list(map(int, stringnum))\r\n# Take a variable say \"evn_sum\" and initialize it with 1.\r\nevn_prodt = 1\r\n# Take another variable say \"od_sum\" and initialize it with 1.\r\nod_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 iterator value of \"digtslst\" to the \"evn_prodt\"\r\n # and store it in the same variable evn_prodt.\r\n evn_prodt *= digtslst[itr]\r\n else:\r\n # If the statement is false, then add the iterator value of \"digtslst\" to the \"od_prodt\"\r\n # and store it in the same variable od_sum.\r\n od_prodt *= digtslst[itr]\r\n# Print \"evn_prodt\" to get the product of all digits at even places in a given number.\r\nprint(\r\n \"The product of all digits at even places in a given number{\", numb, \"} =\", evn_prodt)\r\n# Print \"od_prodt\" to get the product of all digits at odd places in a given number.\r\nprint(\r\n \"The product of all digits at odd places in a given number {\", numb, \"} =\", od_prodt)\r\n<\/pre>\n
Enter some random number = 2134315\r\nThe product of all digits at even places in a given number{ 2134315 } = 90\r\nThe product of all digits at odd places in a given number { 2134315 } = 4<\/pre>\n
\n