{"id":16254,"date":"2021-08-12T09:36:39","date_gmt":"2021-08-12T04:06:39","guid":{"rendered":"https:\/\/python-programs.com\/?p=16254"},"modified":"2021-11-22T18:38:28","modified_gmt":"2021-11-22T13:08:28","slug":"python-program-to-calculate-the-value-of-npr","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-value-of-npr\/","title":{"rendered":"Python Program to Calculate the Value of nPr"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find the Number of Weeks between two Dates<\/a> nPr indicates n permutation r.<\/p>\n The process of organizing all the individuals in a given set to form a sequence is referred to as permutation.<\/p>\n The Given mathematical formula for nPr =n!\/(n-r)!<\/strong><\/p>\n Given the values of n, r and the task is to find the value of nPr .<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to calculate the value of nPr for given values of n,r.<\/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 Find the Number of Weeks between two Dates nPr: nPr indicates n permutation r. The process of organizing all the individuals in a given set to form a sequence is referred to as permutation. The Given mathematical formula for nPr =n!\/(n-r)! Given the values of …<\/p>\n
\nnPr:<\/strong><\/p>\nGiven n value = 5\u00a0\r\nGiven r value = 4<\/pre>\n
The value of nPr for above given n, r values = 120<\/pre>\n
Given n value = 6\r\nGiven r value = 3<\/pre>\n
The value of nPr for above given n, r values = 120<\/pre>\n
Program to Calculate the Value of nPr<\/h2>\n
\n
Method #1: Using math Module (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number as static input and store it in a variable.\r\ngvn_n_val = 5\r\n# Give another number as static input and store it in another variable.\r\ngvn_r_val = 4\r\n# Calculate the value of nPr with reference to standard mathematical formula n!\/(n-r)!\r\n# using factorial() function\u00a0\r\n# Store it in a variable.\r\nn_p_r = math.factorial(gvn_n_val)\/\/math.factorial(gvn_n_val-gvn_r_val)\r\n# Print the value of nPr for the above given n, r values.\r\nprint(\"The value of nPr for above given n, r values = \", n_p_r)\r\n<\/pre>\n
The value of nPr for above given n, r values = 120<\/pre>\n
Method #2: Using math Module (User input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number as user input using the int(input()) function and store it in a variable.\r\ngvn_n_val = int(input(\"Enter some Random number = \"))\r\n# Give another number as user input using\u00a0the\u00a0int(input())\u00a0function and store it in another variable.\r\ngvn_r_val = int(input(\"Enter some Random number = \"))\r\n# Calculate the value of nPr with reference to standard mathematical formula n!\/(n-r)!\r\n# using factorial() function\u00a0\r\n# Store it in a variable.\r\nn_p_r = math.factorial(gvn_n_val)\/\/math.factorial(gvn_n_val-gvn_r_val)\r\n# Print the value of nPr for the above given n, r values.\r\nprint(\"The value of nPr for above given n, r values = \", n_p_r)\r\n<\/pre>\n
Enter some Random number = 6\r\nEnter some Random number = 3\r\nThe value of nPr for above given n, r values = 120<\/pre>\n
\n