Question

6.21 LAB: Permutation and Combination Write two functions called permutation0 and combination0, where permutation0 computes a

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def factorial(n1):
    result = 1
    for x in range(2,n1+1):
        result *= x
    return result

def permutation(n,r):
    return int(factorial(n)/factorial(n-r))

def combination(n,r):
    return int(factorial(n)/(factorial(n-r)*factorial(r)))

def main():
    s = input().split(" ")
    n = int(s[0])
    r = int(s[1])
    print("The permutation is "+str(permutation(n,r))+", and the combination is "+str(combination(n,r))+".")

main()


Note: Please comment below if you have any issues with this code.

Add a comment
Know the answer?
Add Answer to:
6.21 LAB: Permutation and Combination Write two functions called permutation0 and combination0, where permutation0 computes and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 16.17 LAB 7A: Largest number In this lab you will prompt the user to provide you...

    16.17 LAB 7A: Largest number In this lab you will prompt the user to provide you with 3 Integers. Then your program should display the largest of the 3 values. Example of a sample run Enter value 1:7 Enter value 2:15 Enter value 3:3 Largest value is: 15 Enter value 1:7 Enter value 2:7 Enter value 3:2 Largest value is: 7 Enter value 1:-10 Enter value 2 :-20 Enter value 3:-30 Largest value is: -10 ACTIVITY 16.17.1: LAB 7A: Largest...

  • 11.9 Week 11 Lab: 2D Arrays For this lab, you only need to write a single...

    11.9 Week 11 Lab: 2D Arrays For this lab, you only need to write a single user-defined function that analyzes a 2D array of chars. You do NOT need to write any of the code in main0 that calls your function. Make sure to use the template and only add code to the user-defined function. Write a function win0 with the following definition (i.e. prototype): int win(char board17)15), char player) The function win0 should return a 1 if the character...

  • 22.39 LAB 13 C FALL 2019 Overview Demonstrate your ability to use pandas with functions Description...

    22.39 LAB 13 C FALL 2019 Overview Demonstrate your ability to use pandas with functions Description Write a program that reads data from an input file using a DataFrame and displays a subset of data using a method Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format: mpg, cylinders, displacement, horsepower, weight, acceleration, model_year, origin, name 18,9,307,130,3504, 12, 70, usa, chevrolet chevelle malibu 15,8,350,165,3693, 11.5,70, usa, buick skylark...

  • Write a program whose input is two integers and whose output is the two integers swapped....

    Write a program whose input is two integers and whose output is the two integers swapped. Write in C language 7.3 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 38 then the output is: 83 Your program must define and call a function. SwapValues returns the two values in swapped order. void SwapValues(int* userVali, int* userVal2) ACRIVITY 7.3.1: LAB: Swapping variables 0/10 ] main.c...

  • In C PLEASE 1.22 LAB: Using math functions Given three floating-point numbers x, y, and z,...

    In C PLEASE 1.22 LAB: Using math functions Given three floating-point numbers x, y, and z, output x to the power of z, x to the power of (y to the power of 2), the absolute value of y, and the square root of (xy to the power of z). Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.21f", yourValue); Ex: If the input is: 5.0 6.5 3.2 the output is:...

  • PLEASE WRITE IN C++ 2.25 LAB: Driving costs Driving is expensive. Write a program with a...

    PLEASE WRITE IN C++ 2.25 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements. Ex: If the input is: 20.0 3.1599 the output is: 1.58 7.90 63.20 Note:...

  • python 3 8.12 LAB: Python cross reference In addition to editors and compilers, a software developer...

    python 3 8.12 LAB: Python cross reference In addition to editors and compilers, a software developer may use tools to analyze the software they are writing to examine the names being used for variables and functions, and list the line numbers where the variables and functions names appear. For example, consider the following program savings.py used to compute the month to month interest gained from a certificate of deposit: 1: Input the CD APR, no years and initial deposit 2:...

  • In Parts This Skill Builder will require you to write several functions in which loops will...

    In Parts This Skill Builder will require you to write several functions in which loops will be the focus. In addition, some of these function will require you to design and implement finite state machines. So, let's get started! The template below has a class called SkillBuilder6 with a set of skeleton methods provided. The requirements for each method is provided below Left Triangle In the template below, SkillBuilder6 has a method with the following signature: public static String leftRightTriangle...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Python Please, If possible, please continue with/ use code already given File Commands: u/a Write a...

    Python Please, If possible, please continue with/ use code already given File Commands: u/a Write a function named, file_commands, that takes the name of a file as a parameter. The function processes the contents the file as follows: For file lines that begin with the letter 'a', calculate & print the integer average of the numbers on the line. For file lines that begin with the letter 'u', print the upper case format for each word following the u. Sample...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT