{"id":14916,"date":"2021-09-30T11:30:15","date_gmt":"2021-09-30T06:00:15","guid":{"rendered":"https:\/\/python-programs.com\/?p=14916"},"modified":"2021-11-22T18:35:29","modified_gmt":"2021-11-22T13:05:29","slug":"python-program-to-calculate-seed-of-a-number","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-seed-of-a-number\/","title":{"rendered":"Python Program to Calculate Seed of a Number"},"content":{"rendered":"
Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java<\/a> and get a good grip on it for better results in exams or interviews.<\/p>\n We’ll learn how to find the seed of a number in Python in this article.<\/p>\n Seed of a Number:<\/strong><\/p>\n If a number x is the seed of a number n, then:<\/p>\n x * the product of x’s digits equals n.<\/p>\n Given a number, the task is to print all the seeds of the given number.<\/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 the seed of a number in Python<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java and get a good grip on it for better results in exams or interviews. We’ll learn how to find the seed of a number in Python in this article. Seed of a Number: If …<\/p>\nGiven Number =4977<\/pre>\n
79\r\n711<\/pre>\n
Given Number = 138<\/pre>\n
23<\/pre>\n
Program to Calculate Seed of a Number 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\ngvnnumb = 4977\r\n# Loop from 1 to given number using the For loop.\r\nfor it in range(1, gvnnumb+1):\r\n # Check If the iterator value divides the given number\r\n # leaving remainder 0 or not using the If conditional statement.\r\n if(gvnnumb % it == 0):\r\n # Convert the given iterator value into\r\n # list of digits using list(),map(),int() and split() functions.\r\n numbdigi = list(map(int, str(it)))\r\n # Take a variable proddig and initialize its value to 1.\r\n proddig = 1\r\n # Loop in this digits list using another For loop(Nested For loop).\r\n for digit in numbdigi:\r\n # Inside the inner for loop multiply the proddig with the number.\r\n proddig = proddig*digit\r\n\r\n # After the end of the inner For loop Check if proddig*iterator\r\n\r\n # value is equal to the the given number using the If conditional statement.\r\n if(proddig*it == gvnnumb):\r\n # If it is true then print the iterator value.\r\n print(it)\r\n<\/pre>\n
79\r\n711<\/pre>\n
79 * 7 * 9 = 4977\r\n711*1*1*7=4977<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the number as user input using the int(input()) function\r\n# and store it in a variable.\r\ngvnnumb = int(input('Enter some random number = '))\r\n# Loop from 1 to given number using the For loop.\r\nfor it in range(1, gvnnumb+1):\r\n # Check If the iterator value divides the given number\r\n # leaving remainder 0 or not using the If conditional statement.\r\n if(gvnnumb % it == 0):\r\n # Convert the given iterator value into\r\n # list of digits using list(),map(),int() and split() functions.\r\n numbdigi = list(map(int, str(it)))\r\n # Take a variable proddig and initialize its value to 1.\r\n proddig = 1\r\n # Loop in this digits list using another For loop(Nested For loop).\r\n for digit in numbdigi:\r\n # Inside the inner for loop multiply the proddig with the number.\r\n proddig = proddig*digit\r\n\r\n # After the end of the inner For loop Check if proddig*iterator\r\n\r\n # value is equal to the the given number using the If conditional statement.\r\n if(proddig*it == gvnnumb):\r\n # If it is true then print the iterator value.\r\n print(it)\r\n<\/pre>\n
Enter some random number = 138\r\n23<\/pre>\n
23*2*3=138<\/pre>\n
\n